2
* Copyright (c) 2002-2004 JGoodies Karsten Lentzsch. All Rights Reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
7
* o Redistributions of source code must retain the above copyright notice,
8
* this list of conditions and the following disclaimer.
10
* o Redistributions in binary form must reproduce the above copyright notice,
11
* this list of conditions and the following disclaimer in the documentation
12
* and/or other materials provided with the distribution.
14
* o Neither the name of JGoodies Karsten Lentzsch nor the names of
15
* its contributors may be used to endorse or promote products derived
16
* from this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
package com.jgoodies.forms.tutorial.basics;
35
import com.jgoodies.forms.factories.Borders;
36
import com.jgoodies.forms.layout.CellConstraints;
37
import com.jgoodies.forms.layout.FormLayout;
40
* Demonstrates the FormLayout growing options: none, default, weighted.
42
* @author Karsten Lentzsch
43
* @version $Revision: 1.9 $
45
public final class GrowingExample {
48
public static void main(String[] args) {
50
UIManager.setLookAndFeel("com.jgoodies.plaf.plastic.PlasticXPLookAndFeel");
51
} catch (Exception e) {
52
// Likely PlasticXP is not in the class path; ignore.
54
JFrame frame = new JFrame();
55
frame.setTitle("Forms Tutorial :: Growing");
56
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
57
JComponent panel = new GrowingExample().buildPanel();
58
frame.getContentPane().add(panel);
60
frame.setVisible(true);
64
public JComponent buildPanel() {
65
JTabbedPane tabbedPane = new JTabbedPane();
66
tabbedPane.putClientProperty("jgoodies.noContentBorder", Boolean.TRUE);
68
tabbedPane.add("All", buildHorizontalAllExtraSpacePanel());
69
tabbedPane.add("Half", buildHorizontalHalfAndHalfPanel());
70
tabbedPane.add("Percent", buildHorizontalPercentMixedPanel());
71
tabbedPane.add("Percent 2", buildHorizontalPercentPanel());
72
tabbedPane.add("Vertical 1", buildVerticalGrowing1Panel());
73
tabbedPane.add("Vertical 2", buildVerticalGrowing2Panel());
78
private JComponent buildHorizontalAllExtraSpacePanel() {
79
FormLayout layout = new FormLayout(
80
"pref, 6px, pref:grow",
83
JPanel panel = new JPanel(layout);
84
panel.setBorder(Borders.DIALOG_BORDER);
85
CellConstraints cc = new CellConstraints();
87
panel.add(new JLabel("Fixed"), cc.xy(1, 1));
88
panel.add(new JLabel("Gets all extra space"), cc.xy(3, 1));
90
panel.add(new JTextField(5), cc.xy(1, 3));
91
panel.add(new JTextField(5), cc.xy(3, 3));
97
private JComponent buildHorizontalHalfAndHalfPanel() {
98
FormLayout layout = new FormLayout(
99
"pref, 6px, 0:grow, 6px, 0:grow",
102
JPanel panel = new JPanel(layout);
103
panel.setBorder(Borders.DIALOG_BORDER);
104
CellConstraints cc = new CellConstraints();
106
panel.add(new JLabel("Fixed"), cc.xy(1, 1));
107
panel.add(new JLabel("Gets half of extra space"), cc.xy(3, 1));
108
panel.add(new JLabel("gets half of extra space"), cc.xy(5, 1));
110
panel.add(new JTextField(5), cc.xy(1, 3));
111
panel.add(new JTextField(5), cc.xy(3, 3));
112
panel.add(new JTextField(5), cc.xy(5, 3));
118
private JComponent buildHorizontalPercentMixedPanel() {
119
FormLayout layout = new FormLayout(
120
"pref, 6px, 0:grow(0.25), 6px, 0:grow(0.75)",
123
JPanel panel = new JPanel(layout);
124
panel.setBorder(Borders.DIALOG_BORDER);
125
CellConstraints cc = new CellConstraints();
127
panel.add(new JLabel("Fixed"), cc.xy(1, 1));
128
panel.add(new JLabel("Gets 25% of extra space"), cc.xy(3, 1));
129
panel.add(new JLabel("Gets 75% of extra space"), cc.xy(5, 1));
131
panel.add(new JTextField(5), cc.xy(1, 3));
132
panel.add(new JTextField(5), cc.xy(3, 3));
133
panel.add(new JTextField(5), cc.xy(5, 3));
139
private JComponent buildHorizontalPercentPanel() {
140
FormLayout layout = new FormLayout(
141
"pref:grow(0.33), 6px, pref:grow(0.67)",
144
JPanel panel = new JPanel(layout);
145
panel.setBorder(Borders.DIALOG_BORDER);
146
CellConstraints cc = new CellConstraints();
148
panel.add(new JLabel("Gets 33% of the space"), cc.xy(1, 1));
149
panel.add(new JLabel("Gets 67% of the space"), cc.xy(3, 1));
151
panel.add(new JTextField(5), cc.xy(1, 3));
152
panel.add(new JTextField(5), cc.xy(3, 3));
157
private JComponent buildVerticalGrowing1Panel() {
158
FormLayout layout = new FormLayout(
160
"pref, 6px, fill:0:grow(0.25), 6px, fill:0:grow(0.75)");
162
JPanel panel = new JPanel(layout);
163
panel.setBorder(Borders.DIALOG_BORDER);
164
CellConstraints cc = new CellConstraints();
166
panel.add(new JLabel("Fixed"), cc.xy(1, 1));
167
panel.add(new JLabel("Gets 25% of extra space"), cc.xy(1, 3));
168
panel.add(new JLabel("Gets 75% of extra space"), cc.xy(1, 5));
170
panel.add(createTextArea(4, 30), cc.xy(3, 1));
171
panel.add(createTextArea(4, 30), cc.xy(3, 3));
172
panel.add(createTextArea(4, 30), cc.xy(3, 5));
177
private JComponent buildVerticalGrowing2Panel() {
178
FormLayout layout = new FormLayout(
180
"fill:0:grow(0.25), 6px, fill:0:grow(0.75)");
182
JPanel panel = new JPanel(layout);
183
panel.setBorder(Borders.DIALOG_BORDER);
184
CellConstraints cc = new CellConstraints();
186
panel.add(new JLabel("Gets 25% of extra space"), cc.xy(1, 1));
187
panel.add(new JLabel("Gets 75% of extra space"), cc.xy(1, 3));
189
panel.add(createTextArea(4, 30), cc.xy(3, 1));
190
panel.add(createTextArea(4, 30), cc.xy(3, 3));
196
// Component Creation *****************************************************
198
private JComponent createTextArea(int rows, int cols) {
199
return new JScrollPane(new JTextArea(rows, cols),
200
ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER,
201
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);