KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jgoodies > forms > tutorial > building > IndentColumnExample


1 /*
2  * Copyright (c) 2003 JGoodies Karsten Lentzsch. All Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * o Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  *
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.
13  *
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.
17  *
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.
29  */

30
31 package com.jgoodies.forms.tutorial.building;
32
33 import javax.swing.JComponent JavaDoc;
34 import javax.swing.JFrame JavaDoc;
35 import javax.swing.JTextField JavaDoc;
36 import javax.swing.UIManager JavaDoc;
37 import javax.swing.WindowConstants JavaDoc;
38
39 import com.jgoodies.forms.extras.DefaultFormBuilder;
40 import com.jgoodies.forms.layout.FormLayout;
41
42 /**
43  * Demonstrates how to efficiently build a panel with a leading
44  * indent column using the DefaultFormBuilder.
45  *
46  * @author Karsten Lentzsch
47  * @version $Revision: 1.4 $
48  * @see DefaultFormBuilder
49  */

50
51 public final class IndentColumnExample {
52     
53     private JTextField JavaDoc fileNumberField;
54     private JTextField JavaDoc rfqNumberField;
55     private JTextField JavaDoc blNumberField;
56     private JTextField JavaDoc mblNumberField;
57     
58     private JTextField JavaDoc customerKeyField;
59     private JTextField JavaDoc customerAddressField;
60     private JTextField JavaDoc shipperKeyField;
61     private JTextField JavaDoc shipperAddressField;
62     private JTextField JavaDoc consigneeKeyField;
63     private JTextField JavaDoc consigneeAddressField;
64     
65     private JTextField JavaDoc departureCodeField;
66     private JTextField JavaDoc departurePortField;
67     private JTextField JavaDoc destinationCodeField;
68     private JTextField JavaDoc destinationPortField;
69     private JTextField JavaDoc deliveryDateField;
70     
71
72     public static void main(String JavaDoc[] args) {
73         try {
74             UIManager.setLookAndFeel("com.jgoodies.plaf.plastic.PlasticXPLookAndFeel");
75         } catch (Exception JavaDoc e) {
76             // Likely PlasticXP is not in the class path; ignore.
77
}
78         JFrame JavaDoc frame = new JFrame JavaDoc();
79         frame.setTitle("Forms Tutorial :: Indent Column");
80         frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
81         JComponent JavaDoc panel = new FormDebugExample().buildPanel();
82         frame.getContentPane().add(panel);
83         frame.pack();
84         frame.show();
85     }
86
87
88     // Component Creation and Initialization **********************************
89

90     /**
91      * Creates and intializes the UI components.
92      */

93     private void initComponents() {
94         fileNumberField = new JTextField JavaDoc();
95         rfqNumberField = new JTextField JavaDoc();
96         blNumberField = new JTextField JavaDoc();
97         mblNumberField = new JTextField JavaDoc();
98         customerKeyField = new JTextField JavaDoc();
99         customerAddressField = new JTextField JavaDoc();
100         customerAddressField.setEditable(false);
101         shipperKeyField = new JTextField JavaDoc();
102         shipperAddressField = new JTextField JavaDoc();
103         shipperAddressField.setEditable(false);
104         consigneeKeyField = new JTextField JavaDoc();
105         consigneeAddressField = new JTextField JavaDoc();
106         consigneeAddressField.setEditable(false);
107         departureCodeField = new JTextField JavaDoc();
108         departurePortField = new JTextField JavaDoc();
109         departurePortField.setEditable(false);
110         destinationCodeField = new JTextField JavaDoc();
111         destinationPortField = new JTextField JavaDoc();
112         destinationPortField.setEditable(false);
113         deliveryDateField = new JTextField JavaDoc();
114     }
115
116     // Building *************************************************************
117

118     /**
119      * Builds the pane.
120      */

121     public JComponent JavaDoc buildPanel() {
122         initComponents();
123         
124         FormLayout layout = new FormLayout(
125                 "12dlu, pref, 3dlu, max(45dlu;min), 2dlu, min, 2dlu, min, 2dlu, min, ",
126                 "");
127         layout.setColumnGroups(new int[][] { { 4, 6, 8, 10 } });
128         
129         DefaultFormBuilder builder = new DefaultFormBuilder(layout);
130         builder.setDefaultDialogBorder();
131         builder.setLeadingColumnOffset(1);
132
133         builder.appendSeparator("General");
134         builder.append("File Number", fileNumberField, 7);
135         builder.append("RFQ Number", rfqNumberField, 7);
136         builder.append("BL/MBL", blNumberField, mblNumberField); builder.nextLine();
137
138         builder.appendSeparator("Addresses");
139         builder.append("Customer", customerKeyField, customerAddressField, 5);
140         builder.append("Shipper", shipperKeyField, shipperAddressField, 5);
141         builder.append("Consignee", consigneeKeyField, consigneeAddressField, 5);
142
143         builder.appendSeparator("Transport");
144         builder.append("Departure", departureCodeField, departurePortField, 5);
145         builder.append("Destination", destinationCodeField, destinationPortField, 5);
146         builder.append("Delivery Date", deliveryDateField); builder.nextLine();
147         
148         return builder.getPanel();
149     }
150
151
152 }
Popular Tags