GridBagLayout - How grow my columns correctly?



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);
}

.



Relevant Pages

  • Re: Daughters first unicycle
    ... unicycle needs a minimum 18" without major modification, and that he could get it down to 14" by cutting the frame. ... a fair bit of growing still to do! ...
    (uk.rec.cycling)
  • Re: Use of "Frame" by Sports Commentators
    ... "frame" applies to bowling ... as the "frame" substitution but it's growing. ... Sports commentators have to talk like that in order to make sports ...
    (alt.usage.english)
  • Re: GridBagLayout - How grow my columns correctly?
    ... > the 7th column grows on resize and all other are fix (not growing). ... The StreetNo label is NOT growing. ... the tfStreetNo component is aligned in it ... extra space of the previous colunm. ...
    (comp.lang.java.gui)
  • Re: Weird file that grows non-stop (mondump.txt)
    ... How can I stop it from growing? ... > Run oh.exe (Windows Resource Kit) to determine which process ... Prev by Date: ...
    (microsoft.public.windows.server.general)
  • Re: message rules news
    ... growing. ... Handmade example: ... >> Is there a limit to the number of OR conditions you can specify? ... Prev by Date: ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)