Simple Java JTabbedPane Example
Java JTabbedPane class inherits from JComponent class.The main use of JTabbedPane is to switch in between group of components by clicking the tabs.
Java JColorChooser
How declare Java JTabbedPane class
[class JTabbedPane extends JComponent implements Serializable, Accessible, SwingConstants
]
Java JTabbedPane Constructors
- JTabbedPane()-creates empty tabbedPane with default tab at the top.
- JTabbedPane(int tab)-creates a tabbedPane with specified tab placement.
- JTabbedPane(int tab,int layout)-creates tabbedPane with specified layout and placement.
Example
[
import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTabbedPane; import javax.swing.JTextArea; import javax.swing.UIManager; public class JavaJTabbedPaneExample extends JFrame { JavaJTabbedPaneExample () { super("Java JTabbedPane Example"); try { UIManager.setLookAndFeel ("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel"); } catch(Exception e) { e.printStackTrace(); } JTabbedPane pane=new JTabbedPane(); JPanel panel1=new JPanel(); JTextArea area=new JTextArea(200,200); panel1.add(area); JPanel panel2=new JPanel(); JPanel panel3=new JPanel(); pane.addTab("TextArea 1", panel1); pane.addTab("TextArea 2", panel2); pane.addTab("TextArea 3", panel3); pane.setBounds(10,10,200,200); add(pane); setSize(400,300); setLayout(null); setVisible(true); } public static void main(String args[]) { new JavaJTabbedPaneExample(); } }
]
Lessons to Learn in this tutorial
- Creating JTextArea and adding it to a JPanel [JPanel panel1=new JPanel();
JTextArea area=new JTextArea(200,200);
panel1.add(area);] - Setting application LookAndFeel to WindowsLookAndFeel [try
{ UIManager.setLookAndFeel ("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel"); } catch(Exception e) { e.printStackTrace();
}]