Monday, August 3, 2009

TabbedPane – Java Source Code

The below code is the simple source code to create TabbedPane in Swings.


import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

public class TabbedPaneDemo {

TabbedPaneDemo() {
JFrame frame = new JFrame("TabbedPane");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,100);
frame.setResizable(false);
frame.setLocationRelativeTo(null);

JPanel p = new JPanel();
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
JPanel p3 = new JPanel();
JPanel p4 = new JPanel();
JTabbedPane tb = new JTabbedPane();

tb.addTab("Index",null,p,"This is enabled");
tb.addTab("Index",null,p1,"This is disabled");
tb.addTab("Index",null,p2,"This is enabled");
tb.addTab("Index",null,p3,"This is disabled");
tb.addTab("Index",null,p4,"This is enabled");

tb.setEnabledAt(1,false);
tb.setEnabledAt(3,false);

frame.add(tb);

frame.setVisible(true);
}



public static void main(String[] args) {
TabbedPaneDemo tabbedPaneDemo = new TabbedPaneDemo();
}

}


No comments:

Total Pageviews