001: /*
002: * Copyright (c) 2002-2007 JGoodies Karsten Lentzsch. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of JGoodies Karsten Lentzsch nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package com.jgoodies.forms.tutorial.basics;
032:
033: import javax.swing.*;
034:
035: import com.jgoodies.forms.factories.Borders;
036: import com.jgoodies.forms.layout.CellConstraints;
037: import com.jgoodies.forms.layout.FormLayout;
038:
039: /**
040: * Demonstrates the FormLayout growing options: none, default, weighted.
041: *
042: * @author Karsten Lentzsch
043: * @version $Revision: 1.13 $
044: */
045: public final class GrowingExample {
046:
047: public static void main(String[] args) {
048: try {
049: UIManager
050: .setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
051: } catch (Exception e) {
052: // Likely PlasticXP is not in the class path; ignore.
053: }
054: JFrame frame = new JFrame();
055: frame.setTitle("Forms Tutorial :: Growing");
056: frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
057: JComponent panel = new GrowingExample().buildPanel();
058: frame.getContentPane().add(panel);
059: frame.pack();
060: frame.setVisible(true);
061: }
062:
063: public JComponent buildPanel() {
064: JTabbedPane tabbedPane = new JTabbedPane();
065: tabbedPane.putClientProperty("jgoodies.noContentBorder",
066: Boolean.TRUE);
067:
068: tabbedPane.add("All", buildHorizontalAllExtraSpacePanel());
069: tabbedPane.add("Half", buildHorizontalHalfAndHalfPanel());
070: tabbedPane.add("Percent", buildHorizontalPercentMixedPanel());
071: tabbedPane.add("Percent 2", buildHorizontalPercentPanel());
072: tabbedPane.add("Vertical 1", buildVerticalGrowing1Panel());
073: tabbedPane.add("Vertical 2", buildVerticalGrowing2Panel());
074: return tabbedPane;
075: }
076:
077: private JComponent buildHorizontalAllExtraSpacePanel() {
078: FormLayout layout = new FormLayout("pref, 6px, pref:grow",
079: "pref, 12px, pref");
080:
081: JPanel panel = new JPanel(layout);
082: panel.setBorder(Borders.DIALOG_BORDER);
083: CellConstraints cc = new CellConstraints();
084:
085: panel.add(new JLabel("Fixed"), cc.xy(1, 1));
086: panel.add(new JLabel("Gets all extra space"), cc.xy(3, 1));
087:
088: panel.add(new JTextField(5), cc.xy(1, 3));
089: panel.add(new JTextField(5), cc.xy(3, 3));
090:
091: return panel;
092: }
093:
094: private JComponent buildHorizontalHalfAndHalfPanel() {
095: FormLayout layout = new FormLayout(
096: "pref, 6px, 0:grow, 6px, 0:grow", "pref, 12px, pref");
097:
098: JPanel panel = new JPanel(layout);
099: panel.setBorder(Borders.DIALOG_BORDER);
100: CellConstraints cc = new CellConstraints();
101:
102: panel.add(new JLabel("Fixed"), cc.xy(1, 1));
103: panel.add(new JLabel("Gets half of extra space"), cc.xy(3, 1));
104: panel.add(new JLabel("gets half of extra space"), cc.xy(5, 1));
105:
106: panel.add(new JTextField(5), cc.xy(1, 3));
107: panel.add(new JTextField(5), cc.xy(3, 3));
108: panel.add(new JTextField(5), cc.xy(5, 3));
109:
110: return panel;
111: }
112:
113: private JComponent buildHorizontalPercentMixedPanel() {
114: FormLayout layout = new FormLayout(
115: "pref, 6px, 0:grow(0.25), 6px, 0:grow(0.75)",
116: "pref, 12px, pref");
117:
118: JPanel panel = new JPanel(layout);
119: panel.setBorder(Borders.DIALOG_BORDER);
120: CellConstraints cc = new CellConstraints();
121:
122: panel.add(new JLabel("Fixed"), cc.xy(1, 1));
123: panel.add(new JLabel("Gets 25% of extra space"), cc.xy(3, 1));
124: panel.add(new JLabel("Gets 75% of extra space"), cc.xy(5, 1));
125:
126: panel.add(new JTextField(5), cc.xy(1, 3));
127: panel.add(new JTextField(5), cc.xy(3, 3));
128: panel.add(new JTextField(5), cc.xy(5, 3));
129:
130: return panel;
131: }
132:
133: private JComponent buildHorizontalPercentPanel() {
134: FormLayout layout = new FormLayout(
135: "pref:grow(0.33), 6px, pref:grow(0.67)",
136: "pref, 12px, pref");
137:
138: JPanel panel = new JPanel(layout);
139: panel.setBorder(Borders.DIALOG_BORDER);
140: CellConstraints cc = new CellConstraints();
141:
142: panel.add(new JLabel("Gets 33% of the space"), cc.xy(1, 1));
143: panel.add(new JLabel("Gets 67% of the space"), cc.xy(3, 1));
144:
145: panel.add(new JTextField(5), cc.xy(1, 3));
146: panel.add(new JTextField(5), cc.xy(3, 3));
147:
148: return panel;
149: }
150:
151: private JComponent buildVerticalGrowing1Panel() {
152: FormLayout layout = new FormLayout("pref, 12px, pref",
153: "pref, 6px, fill:0:grow(0.25), 6px, fill:0:grow(0.75)");
154:
155: JPanel panel = new JPanel(layout);
156: panel.setBorder(Borders.DIALOG_BORDER);
157: CellConstraints cc = new CellConstraints();
158:
159: panel.add(new JLabel("Fixed"), cc.xy(1, 1));
160: panel.add(new JLabel("Gets 25% of extra space"), cc.xy(1, 3));
161: panel.add(new JLabel("Gets 75% of extra space"), cc.xy(1, 5));
162:
163: panel.add(createTextArea(4, 30), cc.xy(3, 1));
164: panel.add(createTextArea(4, 30), cc.xy(3, 3));
165: panel.add(createTextArea(4, 30), cc.xy(3, 5));
166:
167: return panel;
168: }
169:
170: private JComponent buildVerticalGrowing2Panel() {
171: FormLayout layout = new FormLayout("pref, 12px, pref",
172: "fill:0:grow(0.25), 6px, fill:0:grow(0.75)");
173:
174: JPanel panel = new JPanel(layout);
175: panel.setBorder(Borders.DIALOG_BORDER);
176: CellConstraints cc = new CellConstraints();
177:
178: panel.add(new JLabel("Gets 25% of extra space"), cc.xy(1, 1));
179: panel.add(new JLabel("Gets 75% of extra space"), cc.xy(1, 3));
180:
181: panel.add(createTextArea(4, 30), cc.xy(3, 1));
182: panel.add(createTextArea(4, 30), cc.xy(3, 3));
183:
184: return panel;
185: }
186:
187: // Component Creation *****************************************************
188:
189: private JComponent createTextArea(int rows, int cols) {
190: return new JScrollPane(new JTextArea(rows, cols),
191: ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER,
192: ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
193: }
194:
195: }
|