1 /* ScrollBarDemo.java -- An example showing scroll bars in Swing.
2 Copyright (C) 2005, 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)
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
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
.JFrame
;
32 import javax
.swing
.JPanel
;
33 import javax
.swing
.JScrollBar
;
36 * A simple scroll bar demo showing various scroll bars in different states.
38 public class ScrollBarDemo
40 implements ActionListener
44 * Creates a new demo instance.
46 * @param title the frame title.
48 public ScrollBarDemo(String title
)
51 JPanel content
= createContent();
52 JPanel closePanel
= new JPanel();
53 JButton closeButton
= new JButton("Close");
54 closeButton
.setActionCommand("CLOSE");
55 closeButton
.addActionListener(this);
56 closePanel
.add(closeButton
);
57 content
.add(closePanel
, BorderLayout
.SOUTH
);
58 getContentPane().add(content
);
62 * Returns a panel with the demo content. The panel
63 * uses a BorderLayout(), and the BorderLayout.SOUTH area
64 * is empty, to allow callers to add controls to the
65 * bottom of the panel if they want to (a close button is
66 * added if this demo is being run as a standalone demo).
68 JPanel
createContent()
70 JPanel content
= new JPanel(new BorderLayout());
71 JPanel panel
= createScrollBarPanel();
76 private JPanel
createScrollBarPanel()
78 JPanel panel
= new JPanel(new BorderLayout());
80 JPanel horizontalPanel
= new JPanel();
82 JScrollBar scroll1a
= new JScrollBar(JScrollBar
.HORIZONTAL
);
83 JScrollBar scroll1b
= new JScrollBar(JScrollBar
.HORIZONTAL
);
84 scroll1b
.setEnabled(false);
85 JScrollBar scroll1c
= new JScrollBar(JScrollBar
.HORIZONTAL
);
86 scroll1c
.putClientProperty("JScrollBar.isFreeStanding", Boolean
.FALSE
);
87 JScrollBar scroll1d
= new JScrollBar(JScrollBar
.HORIZONTAL
);
88 scroll1d
.putClientProperty("JScrollBar.isFreeStanding", Boolean
.FALSE
);
89 scroll1d
.setEnabled(false);
90 horizontalPanel
.add(scroll1a
);
91 horizontalPanel
.add(scroll1b
);
92 horizontalPanel
.add(scroll1c
);
93 horizontalPanel
.add(scroll1d
);
95 panel
.add(horizontalPanel
, BorderLayout
.NORTH
);
97 JPanel verticalPanel
= new JPanel();
98 verticalPanel
.setLayout(new GridLayout(1, 7));
100 JScrollBar scroll2a
= new JScrollBar(JScrollBar
.VERTICAL
);
101 JScrollBar scroll2b
= new JScrollBar(JScrollBar
.VERTICAL
);
102 scroll2b
.setEnabled(false);
103 JScrollBar scroll2c
= new JScrollBar(JScrollBar
.VERTICAL
);
104 scroll2c
.putClientProperty("JScrollBar.isFreeStanding", Boolean
.FALSE
);
105 JScrollBar scroll2d
= new JScrollBar(JScrollBar
.VERTICAL
);
106 scroll2d
.setEnabled(false);
107 scroll2d
.putClientProperty("JScrollBar.isFreeStanding", Boolean
.FALSE
);
109 verticalPanel
.add(scroll2a
);
110 verticalPanel
.add(new JPanel());
111 verticalPanel
.add(scroll2b
);
112 verticalPanel
.add(new JPanel());
113 verticalPanel
.add(scroll2c
);
114 verticalPanel
.add(new JPanel());
115 verticalPanel
.add(scroll2d
);
117 panel
.add(verticalPanel
, BorderLayout
.EAST
);
119 JPanel centerPanel
= new JPanel(new GridLayout(1, 2));
120 centerPanel
.add(new JScrollBar(JScrollBar
.HORIZONTAL
));
121 centerPanel
.add(new JScrollBar(JScrollBar
.VERTICAL
));
122 panel
.add(centerPanel
);
126 public void actionPerformed(ActionEvent e
)
128 if (e
.getActionCommand().equals("CLOSE"))
134 public static void main(String
[] args
)
136 ScrollBarDemo app
= new ScrollBarDemo("ScrollBar Demo");
138 app
.setVisible(true);