Java Reference
In-Depth Information
5.
import java.awt.Color;
6.
import javax.swing.*;
7.
8.
public class TabbedPaneFrame extends SimpleFrame
9.
{
10.
11.
private static String picturePath = "./its/TestData/";
12.
13.
public TabbedPaneFrame()
14.
{
15.
// Create a tabbed pane and glue into the frame
16.
JTabbedPane tabbedPane = new JTabbedPane();
17.
this .getContentPane().add(tabbedPane);
18.
19.
// Generate two labels each of which contains an image
// and add them to the tabbed pane
20.
ImageIcon plum = new ImageIcon(picturePath+"plum.png");
21.
JLabel plumLabel = new JLabel(plum);
22.
ImageIcon lime = new ImageIcon(picturePath+"lime.png");
23.
JLabel limeLabel = new JLabel(lime);
24.
25.
26.
tabbedPane.add("Plum",plumLabel);
27.
tabbedPane.add("Lime",limeLabel);
28.
29.
// Generate a red panel from its.SimpleFrameWithPanels.ColorPanel
30.
// and add it.
31.
ColorPanel redPane = new ColorPanel(Color.red);
32.
tabbedPane.add("Red Pane", redPane);
33.
34.
// Generate a text area and add it as the first (0-th)
35.
// component.
36.
JTextArea legend = new JTextArea();
legend.setText("Legend in a JTextArea \ n"+
37.
"JLabel showing a plum \ n"+
38.
"JLabel showing a lime \ n"+
39.
30.
"A red Panel");
tabbedPane.add(legend,0);
41.
tabbedPane.setTitleAt(0,"Legend");
42.
tabbedPane.setSelectedIndex(1);
43.
}
44.
45.
46.
public static void main(String[] args) {
TabbedPaneFrame tpf = new TabbedPaneFrame();
47.
tpf.setSize(300,200);
48.
49.
tpf.showIt("Tabbed Panes",200,200);
50.
}
51.
}
Search WWH ::




Custom Search