Contoh Program Tabbed Panel 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:

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

public class TabbedPaneDemo extends JFrame {
	private JTabbedPane tabPane;
	private JLabel label1, label2, label3;
	private JPanel panel1, panel2, panel3;
	
	public TabbedPaneDemo () {
		super ("Tabbed Pane Demo");
		
		tabPane = new JTabbedPane ();	
		label1 = new JLabel ("Panel pertama", SwingConstants.CENTER);
		panel1 = new JPanel ();
		panel1.add(label1);
		tabPane.addTab ("Tab Pertama", null, panel1, "Panel Pertama");			

		label2 = new JLabel ("Panel kedua", SwingConstants.CENTER);
		panel2 = new JPanel ();
		panel2.setBackground(Color.ORANGE);
		panel2.add(label2);
		Icon icon = new ImageIcon ("images/new.gif");
		tabPane.addTab ("Tab Kedua", icon, panel2, "Panel Kedua");		

		label3 = new JLabel ("Panel ketiga", SwingConstants.CENTER);
		panel3 = new JPanel ();
		panel3.setBackground(Color.YELLOW);
		panel3.setLayout(new BorderLayout());
		panel3.add(new JButton ("North"), BorderLayout.NORTH);
		panel3.add(new JButton ("West"),  BorderLayout.WEST);
		panel3.add(new JButton ("East"),  BorderLayout.EAST);
		panel3.add(new JButton ("South"), BorderLayout.SOUTH);
		panel3.add(label3);
		tabPane.addTab ("Tab Ketiga", null, panel3, "Panel Ketiga");	

		getContentPane().add(tabPane);		

		setSize (400,300);
		setLocationRelativeTo (null);
		setVisible (true);
	}	

	public static void main (String args[]) {
		TabbedPaneDemo test = new TabbedPaneDemo ();
		test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
}

Semoga bermanfaat

Berbagi itu indah...Share on Facebook0Share on Google+0Tweet about this on TwitterShare on LinkedIn0Pin on Pinterest0Digg this