KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > addressbook > gui > util > LabelTextFieldPanel


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16
package org.columba.addressbook.gui.util;
17
18 import java.awt.Component JavaDoc;
19 import java.awt.GridBagConstraints JavaDoc;
20 import java.awt.GridBagLayout JavaDoc;
21 import java.awt.Insets JavaDoc;
22
23 import javax.swing.Box JavaDoc;
24 import javax.swing.JComponent JavaDoc;
25 import javax.swing.JPanel JavaDoc;
26
27 public class LabelTextFieldPanel extends JPanel JavaDoc {
28
29     private GridBagLayout JavaDoc layout;
30
31     private int y = 0;
32
33     public LabelTextFieldPanel() {
34         layout = new GridBagLayout JavaDoc();
35         setLayout(layout);
36     }
37
38     public void addLabel(JComponent JavaDoc label) {
39         GridBagConstraints JavaDoc c = new GridBagConstraints JavaDoc();
40
41         c.gridx = 0;
42         c.gridy = y;
43         c.weightx = 0.0;
44         c.anchor = GridBagConstraints.WEST;
45         c.fill = GridBagConstraints.HORIZONTAL;
46         c.insets = new Insets JavaDoc(0, 0, 0, 11);
47         layout.setConstraints(label, c);
48         add(label);
49     }
50
51     public void addTextField(JComponent JavaDoc component) {
52         GridBagConstraints JavaDoc c = new GridBagConstraints JavaDoc();
53
54         c.gridx = 1;
55         c.weightx = 1.0;
56         c.gridy = y;
57         c.fill = GridBagConstraints.HORIZONTAL;
58         c.insets = new Insets JavaDoc(5, 0, 0, 0);
59         c.anchor = GridBagConstraints.EAST;
60         c.gridwidth = GridBagConstraints.REMAINDER;
61         layout.setConstraints(component, c);
62         add(component);
63
64         y += 1;
65     }
66
67     public void addSeparator() {
68         GridBagConstraints JavaDoc c = new GridBagConstraints JavaDoc();
69         c.gridx = 0;
70         c.weightx = 1.0;
71         c.gridy = y;
72         c.fill = GridBagConstraints.HORIZONTAL;
73         c.insets = new Insets JavaDoc(0, 0, 0, 0);
74         c.gridwidth = GridBagConstraints.REMAINDER;
75
76         Component JavaDoc component = Box.createVerticalStrut(11);
77         layout.setConstraints(component, c);
78         add(component);
79
80         y += 1;
81     }
82 }
83
Popular Tags