Cara Penggunaan Component Tabbed Di Java

Contoh program berikut ini mendemonstrasikan bagaimana membuat panel-panel dalam bentuk Tab di java. Class yang digunakan adalah JTabbedPane.
Berikut ini tampilannya:

contoh-program-tabbed-java

Berikut ini contoh programnya:
01import java.awt.*;
02import java.awt.event.*;
03import javax.swing.*;
04 
05public class TabbedPaneDemo extends JFrame {
06    private JTabbedPane tabPane;
07    private JLabel label1, label2, label3;
08    private JPanel panel1, panel2, panel3;
09 
10    public TabbedPaneDemo () {
11        super ("Tabbed Pane Demo");
12 
13        tabPane = new JTabbedPane ();
14        label1 = new JLabel ("Panel pertama", SwingConstants.CENTER);
15        panel1 = new JPanel ();
16        panel1.add(label1);
17        tabPane.addTab ("Tab Pertama", null, panel1, "Panel Pertama");         
18 
19        label2 = new JLabel ("Panel kedua", SwingConstants.CENTER);
20        panel2 = new JPanel ();
21        panel2.setBackground(Color.ORANGE);
22        panel2.add(label2);
23        Icon icon = new ImageIcon ("images/new.gif");
24        tabPane.addTab ("Tab Kedua", icon, panel2, "Panel Kedua");     
25 
26        label3 = new JLabel ("Panel ketiga", SwingConstants.CENTER);
27        panel3 = new JPanel ();
28        panel3.setBackground(Color.YELLOW);
29        panel3.setLayout(new BorderLayout());
30        panel3.add(new JButton ("North"), BorderLayout.NORTH);
31        panel3.add(new JButton ("West"),  BorderLayout.WEST);
32        panel3.add(new JButton ("East"),  BorderLayout.EAST);
33        panel3.add(new JButton ("South"), BorderLayout.SOUTH);
34        panel3.add(label3);
35        tabPane.addTab ("Tab Ketiga", null, panel3, "Panel Ketiga");   
36 
37        getContentPane().add(tabPane);     
38 
39        setSize (400,300);
40        setLocationRelativeTo (null);
41        setVisible (true);
42    }  
43 
44    public static void main (String args[]) {
45        TabbedPaneDemo test = new TabbedPaneDemo ();
46        test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
47    }
48}
Semoga bermanfaat