Imported GNU Classpath 0.90
[official-gcc.git] / libjava / classpath / examples / gnu / classpath / examples / swing / ScrollBarDemo.java
blob505991e1918ce9eae033606dd81135e99641e5bd
1 /* ScrollBarDemo.java -- An example showing scroll bars in Swing.
2 Copyright (C) 2005, 2006, Free Software Foundation, Inc.
4 This file is part of GNU Classpath examples.
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)
9 any later version.
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
19 02110-1301 USA.
23 package gnu.classpath.examples.swing;
25 import java.awt.BorderLayout;
26 import java.awt.GridLayout;
27 import java.awt.event.ActionEvent;
28 import java.awt.event.ActionListener;
30 import javax.swing.JButton;
31 import javax.swing.JComponent;
32 import javax.swing.JFrame;
33 import javax.swing.JPanel;
34 import javax.swing.JScrollBar;
35 import javax.swing.SwingUtilities;
37 /**
38 * A simple scroll bar demo showing various scroll bars in different states.
40 public class ScrollBarDemo
41 extends JPanel
42 implements ActionListener
45 /**
46 * Creates a new demo instance.
48 public ScrollBarDemo()
50 super();
51 createContent();
54 /**
55 * When the demo is run independently, the frame is displayed, so we should
56 * initialise the content panel (including the demo content and a close
57 * button). But when the demo is run as part of the Swing activity board,
58 * only the demo content panel is used, the frame itself is never displayed,
59 * so we can avoid this step.
61 void initFrameContent()
63 JPanel closePanel = new JPanel();
64 JButton closeButton = new JButton("Close");
65 closeButton.setActionCommand("CLOSE");
66 closeButton.addActionListener(this);
67 closePanel.add(closeButton);
68 add(closePanel, BorderLayout.SOUTH);
71 /**
72 * Returns a panel with the demo content. The panel
73 * uses a BorderLayout(), and the BorderLayout.SOUTH area
74 * is empty, to allow callers to add controls to the
75 * bottom of the panel if they want to (a close button is
76 * added if this demo is being run as a standalone demo).
77 */
78 private void createContent()
80 setLayout(new BorderLayout());
81 JPanel panel = createScrollBarPanel();
82 add(panel);
85 private JPanel createScrollBarPanel()
87 JPanel panel = new JPanel(new BorderLayout());
89 JPanel horizontalPanel = new JPanel();
91 JScrollBar scroll1a = new JScrollBar(JScrollBar.HORIZONTAL);
92 JScrollBar scroll1b = new JScrollBar(JScrollBar.HORIZONTAL);
93 scroll1b.setEnabled(false);
94 JScrollBar scroll1c = new JScrollBar(JScrollBar.HORIZONTAL);
95 scroll1c.putClientProperty("JScrollBar.isFreeStanding", Boolean.FALSE);
96 JScrollBar scroll1d = new JScrollBar(JScrollBar.HORIZONTAL);
97 scroll1d.putClientProperty("JScrollBar.isFreeStanding", Boolean.FALSE);
98 scroll1d.setEnabled(false);
99 horizontalPanel.add(scroll1a);
100 horizontalPanel.add(scroll1b);
101 horizontalPanel.add(scroll1c);
102 horizontalPanel.add(scroll1d);
104 panel.add(horizontalPanel, BorderLayout.NORTH);
106 JPanel verticalPanel = new JPanel();
107 verticalPanel.setLayout(new GridLayout(1, 7));
109 JScrollBar scroll2a = new JScrollBar(JScrollBar.VERTICAL);
110 JScrollBar scroll2b = new JScrollBar(JScrollBar.VERTICAL);
111 scroll2b.setEnabled(false);
112 JScrollBar scroll2c = new JScrollBar(JScrollBar.VERTICAL);
113 scroll2c.putClientProperty("JScrollBar.isFreeStanding", Boolean.FALSE);
114 JScrollBar scroll2d = new JScrollBar(JScrollBar.VERTICAL);
115 scroll2d.setEnabled(false);
116 scroll2d.putClientProperty("JScrollBar.isFreeStanding", Boolean.FALSE);
118 verticalPanel.add(scroll2a);
119 verticalPanel.add(new JPanel());
120 verticalPanel.add(scroll2b);
121 verticalPanel.add(new JPanel());
122 verticalPanel.add(scroll2c);
123 verticalPanel.add(new JPanel());
124 verticalPanel.add(scroll2d);
126 panel.add(verticalPanel, BorderLayout.EAST);
128 JPanel centerPanel = new JPanel(new GridLayout(1, 2));
129 centerPanel.add(new JScrollBar(JScrollBar.HORIZONTAL));
130 centerPanel.add(new JScrollBar(JScrollBar.VERTICAL));
131 panel.add(centerPanel);
132 return panel;
135 public void actionPerformed(ActionEvent e)
137 if (e.getActionCommand().equals("CLOSE"))
139 System.exit(0);
143 public static void main(String[] args)
145 SwingUtilities.invokeLater
146 (new Runnable()
148 public void run()
150 ScrollBarDemo app = new ScrollBarDemo();
151 app.initFrameContent();
152 JFrame frame = new JFrame("ScrollBar Demo");
153 frame.getContentPane().add(app);
154 frame.pack();
155 frame.setVisible(true);
156 }});
160 * Returns a DemoFactory that creates a ScrollBarDemo.
162 * @return a DemoFactory that creates a ScrollBarDemo
164 public static DemoFactory createDemoFactory()
166 return new DemoFactory()
168 public JComponent createDemo()
170 return new ScrollBarDemo();