1
36
37
40
41
42 import javax.swing.*;
43 import javax.swing.event.*;
44 import javax.swing.text.*;
45 import javax.swing.table.*;
46 import javax.swing.border.*;
47 import javax.swing.colorchooser.*;
48 import javax.swing.filechooser.*;
49 import javax.accessibility.*;
50
51 import java.awt.*;
52 import java.awt.event.*;
53 import java.beans.*;
54 import java.util.*;
55 import java.io.*;
56 import java.applet.*;
57 import java.net.*;
58
59
66 public class SplitPaneDemo extends DemoModule {
67
68 JSplitPane splitPane = null;
69 JLabel earth = null;
70 JLabel moon = null;
71
72 JTextField divSize;
73 JTextField earthSize;
74 JTextField moonSize;
75
76
79 public static void main(String[] args) {
80 SplitPaneDemo demo = new SplitPaneDemo(null);
81 demo.mainImpl();
82 }
83
84
87 public SplitPaneDemo(SwingSet2 swingset) {
88 super(swingset, "SplitPaneDemo", "toolbar/JSplitPane.gif");
89
90 earth = new JLabel(createImageIcon("splitpane/earth.jpg", getString("SplitPaneDemo.earth")));
91 earth.setMinimumSize(new Dimension(20, 20));
92
93 moon = new JLabel(createImageIcon("splitpane/moon.jpg", getString("SplitPaneDemo.moon")));
94 moon.setMinimumSize(new Dimension(20, 20));
95
96 splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, earth, moon);
97 splitPane.setContinuousLayout(true);
98 splitPane.setOneTouchExpandable(true);
99
100 splitPane.setDividerLocation(200);
101
102 getDemoPanel().add(splitPane, BorderLayout.CENTER);
103 getDemoPanel().setBackground(Color.black);
104
105 getDemoPanel().add(createSplitPaneControls(), BorderLayout.SOUTH);
106 }
107
108
111 protected JPanel createSplitPaneControls() {
112 JPanel wrapper = new JPanel();
113 ButtonGroup group = new ButtonGroup();
114 JRadioButton button;
115
116 Box buttonWrapper = new Box(BoxLayout.X_AXIS);
117
118 wrapper.setLayout(new GridLayout(0, 1));
119
120
121 button = new JRadioButton(getString("SplitPaneDemo.vert_split"));
122 button.setMnemonic(getMnemonic("SplitPaneDemo.vert_split_mnemonic"));
123 button.addActionListener(new ActionListener() {
124 public void actionPerformed(ActionEvent e) {
125 splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
126 }
127 });
128 group.add(button);
129 buttonWrapper.add(button);
130
131
132 button = new JRadioButton(getString("SplitPaneDemo.horz_split"));
133 button.setMnemonic(getMnemonic("SplitPaneDemo.horz_split_mnemonic"));
134 button.setSelected(true);
135 button.addActionListener(new ActionListener() {
136 public void actionPerformed(ActionEvent e) {
137 splitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
138 }
139 });
140 group.add(button);
141 buttonWrapper.add(button);
142
143
145 JCheckBox checkBox = new JCheckBox(getString("SplitPaneDemo.cont_layout"));
146 checkBox.setMnemonic(getMnemonic("SplitPaneDemo.cont_layout_mnemonic"));
147 checkBox.setSelected(true);
148
149 checkBox.addChangeListener(new ChangeListener() {
150 public void stateChanged(ChangeEvent e) {
151 splitPane.setContinuousLayout(
152 ((JCheckBox)e.getSource()).isSelected());
153 }
154 });
155 buttonWrapper.add(checkBox);
156
157
159 checkBox = new JCheckBox(getString("SplitPaneDemo.one_touch_expandable"));
160 checkBox.setMnemonic(getMnemonic("SplitPaneDemo.one_touch_expandable_mnemonic"));
161 checkBox.setSelected(true);
162
163 checkBox.addChangeListener(new ChangeListener() {
164 public void stateChanged(ChangeEvent e) {
165 splitPane.setOneTouchExpandable(
166 ((JCheckBox) e.getSource()).isSelected());
167 }
168 });
169 buttonWrapper.add(checkBox);
170 wrapper.add(buttonWrapper);
171
172
173 JPanel tfWrapper;
174 JLabel label;
175
176 divSize = new JTextField();
177 divSize.setText(new Integer(splitPane.getDividerSize()).toString());
178 divSize.setColumns(5);
179 divSize.getAccessibleContext().setAccessibleName(getString("SplitPaneDemo.divider_size"));
180 divSize.addActionListener(new ActionListener() {
181 public void actionPerformed(ActionEvent e) {
182 String value = ((JTextField)e.getSource()).getText();
183 int newSize;
184
185 try {
186 newSize = Integer.parseInt(value);
187 } catch (Exception ex) {
188 newSize = -1;
189 }
190 if(newSize > 0) {
191 splitPane.setDividerSize(newSize);
192 } else {
193 JOptionPane.showMessageDialog(splitPane,
194 getString("SplitPaneDemo.invalid_divider_size"),
195 getString("SplitPaneDemo.error"),
196 JOptionPane.ERROR_MESSAGE);
197 }
198 }
199 });
200 label = new JLabel(getString("SplitPaneDemo.divider_size"));
201 tfWrapper = new JPanel(new FlowLayout(FlowLayout.LEFT));
202 tfWrapper.add(label);
203 tfWrapper.add(divSize);
204 label.setLabelFor(divSize);
205 label.setDisplayedMnemonic(getMnemonic("SplitPaneDemo.divider_size_mnemonic"));
206 wrapper.add(tfWrapper);
207
208
210 earthSize = new JTextField(String.valueOf(earth.getMinimumSize().width));
211 earthSize.setColumns(5);
212 earthSize.getAccessibleContext().setAccessibleName(getString("SplitPaneDemo.first_component_min_size"));
213 earthSize.addActionListener(new ActionListener() {
214 public void actionPerformed(ActionEvent e) {
215 String value = ((JTextField)e.getSource()).getText();
216 int newSize;
217
218 try {
219 newSize = Integer.parseInt(value);
220 } catch (Exception ex) {
221 newSize = -1;
222 }
223 if(newSize > 10) {
224 earth.setMinimumSize(new Dimension(newSize, newSize));
225 } else {
226 JOptionPane.showMessageDialog(splitPane,
227 getString("SplitPaneDemo.invalid_min_size") +
228 getString("SplitPaneDemo.must_be_greater_than") + 10,
229 getString("SplitPaneDemo.error"),
230 JOptionPane.ERROR_MESSAGE);
231 }
232 }
233 });
234 label = new JLabel(getString("SplitPaneDemo.first_component_min_size"));
235 tfWrapper = new JPanel(new FlowLayout(FlowLayout.LEFT));
236 tfWrapper.add(label);
237 tfWrapper.add(earthSize);
238 label.setLabelFor(earthSize);
239 label.setDisplayedMnemonic(getMnemonic("SplitPaneDemo.first_component_min_size_mnemonic"));
240 wrapper.add(tfWrapper);
241
242
244 moonSize = new JTextField(String.valueOf(moon.getMinimumSize().width));
245 moonSize.setColumns(5);
246 moonSize.getAccessibleContext().setAccessibleName(getString("SplitPaneDemo.second_component_min_size"));
247 moonSize.addActionListener(new ActionListener() {
248 public void actionPerformed(ActionEvent e) {
249 String value = ((JTextField)e.getSource()).getText();
250 int newSize;
251
252 try {
253 newSize = Integer.parseInt(value);
254 } catch (Exception ex) {
255 newSize = -1;
256 }
257 if(newSize > 10) {
258 moon.setMinimumSize(new Dimension(newSize, newSize));
259 } else {
260 JOptionPane.showMessageDialog(splitPane,
261 getString("SplitPaneDemo.invalid_min_size") +
262 getString("SplitPaneDemo.must_be_greater_than") + 10,
263 getString("SplitPaneDemo.error"),
264 JOptionPane.ERROR_MESSAGE);
265 }
266 }
267 });
268 label = new JLabel(getString("SplitPaneDemo.second_component_min_size"));
269 tfWrapper = new JPanel(new FlowLayout(FlowLayout.LEFT));
270 tfWrapper.add(label);
271 tfWrapper.add(moonSize);
272 label.setLabelFor(moonSize);
273 label.setDisplayedMnemonic(getMnemonic("SplitPaneDemo.second_component_min_size_mnemonic"));
274 wrapper.add(tfWrapper);
275
276 return wrapper;
277 }
278
279 void updateDragEnabled(boolean dragEnabled) {
280 divSize.setDragEnabled(dragEnabled);
281 earthSize.setDragEnabled(dragEnabled);
282 moonSize.setDragEnabled(dragEnabled);
283 }
284
285 }
286