Thursday, July 9, 2009

Using Tabbed Panes in Java Swings

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.

Home

0 comments:

About This Blog

This Blog is all about Java and programming.This blog is written by Vaibhav Pandey .He is a Computer Science Graduate .You can contact the author at javatute@gmail.com for any suggestion or Query.You can also contact the author for advertising on this blog.All the material presented here is the property of author and its reproduction in any form is strictly prohibited.

Disclaimer:-Download links provided here are not of author in any means.These are found over the Internet.
Page copy protected against web site content infringement by Copyscape

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Back to TOP