Thursday, July 8, 2010

Using Tabbed Panes in Java Swings  

0 comments

Tabbed panes are just like property sheets in windows environment.Using tabbed pane you can create multiple panels that are visible in a single area.A Tabbed pane consist of series of Tabs.These tabs are present on the basis of categories of information or application they contain.A tabbed pane enables you to display information in a small area in a more effective manner.The JTabbedPane class of javax.swing package is used to create Tabbed panes.Tabbed panes are effective way to use the window area.Tabbed Panes looks like following:-


Tabbed Pane source code:-

import javax.swing.*;
import java.awt.*;

public class Tabbedpane extends JFrame{
public static void main(String a[]){

//creating a container JFrame
JFrame frm=new JFrame("Tabbed Pane");

//Creating Tabbedpane
JTabbedPane jtpn=new JTabbedPane();
JPanel color=new JPanel();

//adding panel to a tabbed pane
jtpn.addTab("Color",null,color,"Color info");
color.add(new JLabel("The color is not set yet"));
JPanel sound=new JPanel();

//adding panel to a tabbed pane
jtpn.addTab("Sound",null,sound,"Sound info");
sound.add(new JLabel("The sound is off"));

//adding component to the container
frm.getContentPane().add(jtpn);
frm.setBounds(200,200,200,200);
frm.show();

}
}

JTabbedPane class is used to ceate JTabbedPane oblect.
For adding a JPanel to a JTabbedPane method named addTab() is used.
Four parameters of addTab() method are:-

1.Label for Tab.
2.Image(if any otherwise null).
3.Component to be added to the Tabbed pane.
4.ToolTip for the tab.

What next?

You can also bookmark this post using your favorite bookmarking service:

Related Posts by Categories



Extension Factory Builder