GridBagLayout - How grow my columns correctly?
- From: "newgro" <per.newgro@xxxxxx>
- Date: 26 Jun 2005 23:39:22 -0700
Hi all,
in advance i coded a small frame. My problem is, that i don't
understand, why the StreetNo label is growing. I thought
the 7th column grows on resize and all other are fix (not growing).
Can somebody give me a tip how i can achieve that only last part of
tfStreetName and 2nd part of tfCity can grow????.
import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import de.coresd.swing.SwingConstants;
/**
* Panel representing data of postal addresses
*/
public class TestAddressEditPanel extends JPanel {
/* the labels section*/
private JLabel lblStreetName = null;
private JLabel lblStreetNo = null;
private JLabel lblPostBoxNo = null;
private JLabel lblPostCode = null;
private JLabel lblCity = null;
private JLabel lblCountry = null;
/* the textfield section */
private JTextField tfStreetName = null;
private JTextField tfStreetNo = null;
private JTextField tfPostBoxNo = null;
private JTextField tfPostCode = null;
private JTextField tfCity = null;
/* the combo section */
private JComboBox cbCountry = null;
/**
* Constructor for TestAddressEditPanel
*/
public TestAddressEditPanel() {
super();
init();
}
/**
* Initialize panel.
*/
private void init() {
setLayout(new GridBagLayout());
tfStreetName = new JTextField();
lblStreetName = new JLabel("Street");
lblStreetName.setLabelFor(tfStreetName);
tfStreetNo = new JTextField(8);
lblStreetNo = new JLabel("No");
lblStreetNo.setLabelFor(tfStreetNo);
tfPostBoxNo = new JTextField(15);
lblPostBoxNo = new JLabel("Postbox");
lblPostBoxNo.setLabelFor(tfPostBoxNo);
cbCountry = new JComboBox();
lblCountry = new JLabel("Country");
lblCountry.setLabelFor(cbCountry);
tfPostCode = new JTextField(5);
lblPostCode = new JLabel("Postcode");
lblPostCode.setLabelFor(tfPostCode);
tfCity = new JTextField();
lblCity = new JLabel("City");
lblCity.setLabelFor(tfCity);
initLayout();
}
/**
* Layout container and components.
*/
private void initLayout() {
add(lblStreetName, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.LINE_END, GridBagConstraints.NONE,
SwingConstants.INSETS_MIDDLE, 0, 0));
add(tfStreetName, new GridBagConstraints(1, 0, 6, 1, 1.0, 0.0,
GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL,
SwingConstants.INSETS_MIDDLE, 0, 0)); // growing
add(lblStreetNo, new GridBagConstraints(7, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.LINE_END, GridBagConstraints.NONE,
SwingConstants.INSETS_MIDDLE, 0, 0)); // fix at end
add(tfStreetNo, new GridBagConstraints(8, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.LINE_END, GridBagConstraints.NONE,
SwingConstants.INSETS_MIDDLE, 0, 0)); fix at end
add(lblPostBoxNo, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
GridBagConstraints.LINE_END, GridBagConstraints.NONE,
SwingConstants.INSETS_MIDDLE, 0, 0));
add(tfPostBoxNo, new GridBagConstraints(1, 1, 5, 1, 0.0, 0.0,
GridBagConstraints.LINE_START, GridBagConstraints.NONE,
SwingConstants.INSETS_MIDDLE, 0, 0));
add(lblCountry, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
GridBagConstraints.LINE_END, GridBagConstraints.NONE,
SwingConstants.INSETS_MIDDLE, 0, 0));
add(cbCountry, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0,
GridBagConstraints.LINE_START, GridBagConstraints.NONE,
SwingConstants.INSETS_MIDDLE, 0, 0));
add(lblPostCode, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0,
GridBagConstraints.LINE_END, GridBagConstraints.NONE,
SwingConstants.INSETS_MIDDLE, 0, 0));
add(tfPostCode, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0,
GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL,
SwingConstants.INSETS_MIDDLE, 0, 0));
add(lblCity, new GridBagConstraints(4, 2, 1, 1, 0.0, 0.0,
GridBagConstraints.LINE_START, GridBagConstraints.NONE,
SwingConstants.INSETS_MIDDLE, 0, 0)); // fix at start
add(tfCity, new GridBagConstraints(5, 2, 4, 1, 1.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
SwingConstants.INSETS_MIDDLE, 0, 0)); // grow to end
}
/**
* Start the test frame.
* @param args unused
*/
public static void main(String[] args) {
JFrame frame = new JFrame("Testadress");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(new TestAddressEditPanel(),
BorderLayout.CENTER);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
.
- Follow-Ups:
- Re: GridBagLayout - How grow my columns correctly?
- From: A. Bolmarcich
- Re: GridBagLayout - How grow my columns correctly?
- From: Andrew Thompson
- Re: GridBagLayout - How grow my columns correctly?
- Prev by Date: HUMAN SOFTWARE WEBSPHERE DEVELOPMENT NETWORK : you're welcome
- Next by Date: Re: GridBagLayout - How grow my columns correctly?
- Previous by thread: HUMAN SOFTWARE WEBSPHERE DEVELOPMENT NETWORK : you're welcome
- Next by thread: Re: GridBagLayout - How grow my columns correctly?
- Index(es):
Relevant Pages
|
|