01: package tools.tracesviewer;
02:
03: import javax.swing.JTabbedPane;
04: import javax.swing.ImageIcon;
05: import javax.swing.JLabel;
06: import javax.swing.JPanel;
07: import javax.swing.JFrame;
08:
09: import java.awt.*;
10: import java.awt.event.*;
11:
12: public class TabbedPaneDemo extends JPanel {
13: public TabbedPaneDemo() {
14: ImageIcon icon = new ImageIcon("images/middle.gif");
15: JTabbedPane tabbedPane = new JTabbedPane();
16:
17: Component panel1 = makeTextPanel("Blah");
18: tabbedPane.addTab("One", icon, panel1, "Does nothing");
19: tabbedPane.setSelectedIndex(0);
20:
21: Component panel2 = makeTextPanel("Blah blah");
22: tabbedPane.addTab("Two", icon, panel2,
23: "Does twice as much nothing");
24:
25: Component panel3 = makeTextPanel("Blah blah blah");
26: tabbedPane.addTab("Three", icon, panel3, "Still does nothing");
27:
28: Component panel4 = makeTextPanel("Blah blah blah blah");
29: tabbedPane.addTab("Four", icon, panel4, "Does nothing at all");
30:
31: //Add the tabbed pane to this panel.
32: setLayout(new GridLayout(1, 1));
33: add(tabbedPane);
34: }
35:
36: protected Component makeTextPanel(String text) {
37: JPanel panel = new JPanel(false);
38: JLabel filler = new JLabel(text);
39: filler.setHorizontalAlignment(JLabel.CENTER);
40: panel.setLayout(new GridLayout(1, 1));
41: panel.add(filler);
42: return panel;
43: }
44:
45: public static void main(String[] args) {
46: JFrame frame = new JFrame("TabbedPaneDemo");
47: frame.addWindowListener(new WindowAdapter() {
48: public void windowClosing(WindowEvent e) {
49: System.exit(0);
50: }
51: });
52:
53: frame.getContentPane().add(new TabbedPaneDemo(),
54: BorderLayout.CENTER);
55: frame.setSize(400, 125);
56: frame.setVisible(true);
57: }
58: }
|