1
/* TabbedPaneDemo.java -- Demonstrates JTabbedPane
2
Copyright (C) 2006 Free Software Foundation, Inc.
4
This file is part of GNU Classpath.
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING. If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library. Thus, the terms and
23
conditions of the GNU General Public License cover the whole
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module. An independent module is a module which is not derived from
33
or based on this library. If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so. If you do not wish to do so, delete this
36
exception statement from your version. */
39
package gnu.classpath.examples.swing;
41
import java.awt.BorderLayout;
42
import java.awt.GridLayout;
43
import java.awt.event.ActionEvent;
44
import java.awt.event.ActionListener;
46
import javax.swing.JButton;
47
import javax.swing.JComponent;
48
import javax.swing.JFrame;
49
import javax.swing.JPanel;
50
import javax.swing.JTabbedPane;
51
import javax.swing.SwingConstants;
52
import javax.swing.SwingUtilities;
54
public class TabbedPaneDemo
56
implements ActionListener
64
private void createContent()
66
JPanel p = new JPanel();
67
p.setLayout(new GridLayout(2, 2));
68
JTabbedPane tabs1 = new JTabbedPane(SwingConstants.TOP);
69
tabs1.add("Top Item 1", new JButton("Button"));
70
tabs1.add("Top Item 2", new JButton("Button"));
71
JTabbedPane tabs2 = new JTabbedPane(SwingConstants.LEFT);
72
tabs2.add("Left Item 1", new JButton("Button"));
73
tabs2.add("Left Item 2", new JButton("Button"));
74
JTabbedPane tabs3 = new JTabbedPane(SwingConstants.BOTTOM);
75
tabs3.add("Bottom Item 1", new JButton("Button"));
76
tabs3.add("Bottom Item 2", new JButton("Button"));
77
JTabbedPane tabs4 = new JTabbedPane(SwingConstants.RIGHT);
78
tabs4.add("Right Item 1", new JButton("Button"));
79
tabs4.add("Right Item 2", new JButton("Button"));
84
setLayout(new BorderLayout());
85
add(p, BorderLayout.CENTER);
88
public void actionPerformed(ActionEvent e)
90
if (e.getActionCommand().equals("CLOSE"))
97
* When the demo is run independently, the frame is displayed, so we should
98
* initialise the content panel (including the demo content and a close
99
* button). But when the demo is run as part of the Swing activity board,
100
* only the demo content panel is used, the frame itself is never displayed,
101
* so we can avoid this step.
103
void initFrameContent()
105
JPanel closePanel = new JPanel();
106
JButton closeButton = new JButton("Close");
107
closeButton.setActionCommand("CLOSE");
108
closeButton.addActionListener(this);
109
closePanel.add(closeButton);
110
add(closePanel, BorderLayout.SOUTH);
113
public static void main(String[] args)
115
SwingUtilities.invokeLater
120
TabbedPaneDemo app = new TabbedPaneDemo();
121
app.initFrameContent();
122
JFrame frame = new JFrame("TabbedPane Demo");
123
frame.getContentPane().add(app);
125
frame.setVisible(true);
131
* Returns a DemoFactory that creates a TabbedPaneDemo.
133
* @return a DemoFactory that creates a TabbedPaneDemo
135
public static DemoFactory createDemoFactory()
137
return new DemoFactory()
139
public JComponent createDemo()
141
return new TabbedPaneDemo();