Examples The following program demonstrates how to make the panels in the form of Tab in java. JTabbedPane class is used.
The following looks:
Here is an example program:
01 import java.awt .*;
02 import java.awt.event .*;
03 import javax.swing .*;
04
05 public class extends JFrame {TabbedPaneDemo
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 ("first panel", SwingConstants.CENTER);
15 Panel1 = new JPanel ();
16 panel1.add (label1);
17 tabPane.addTab ("First Tab", null, Panel1, "First Panel");
18
19 label2 = new JLabel ("second panel", 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 ("Second Tab" icon, panel2, "Second Panel");
25
26 label3 = new JLabel ("third panel", 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 Three", null, panel3, "Third Panel");
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 TabbedPaneDemo test = new ();
46 test.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
47}
48}
may be useful
Langganan:
Posting Komentar (Atom)
0 komentar: