GridBagConstraints anchor issue


J

Joris Bleys

Hello everyone,

I've got a little problem getting my GUI as I want.
This is the code I got, but fieldSeperatorLabel isn't at the
rightmost of its cell. It is in the West-side.

JPanel generalPanel = new JPanel();
generalPanel.setLayout(new GridBagLayout());
generalPanel.setBorder(BorderFactory.createTitledBorder(this.general));
GridBagConstraints constraints = new GridBagConstraints();
constraints.ipadx = 4;

constraints.gridx = 0;
constraints.gridy = 0;
generalPanel.add(filenameLabel, constraints);
constraints.gridx = 4;
constraints.gridy = 0;
generalPanel.add(this.browseButton, constraints);
constraints.gridx = 0;
constraints.gridy = 1;
generalPanel.add(recordSeperatorLabel,constraints);
constraints.gridx = 1;
constraints.gridy = 1;
generalPanel.add(this.recordSeperatorField, constraints);
constraints.gridx = 2;
constraints.gridy = 1;
constraints.anchor = GridBagConstraints.EAST;
generalPanel.add(fieldSeperatorLabel, constraints);
constraints.gridx = 3;
constraints.gridy = 1;
constraints.anchor = GridBagConstraints.CENTER;
generalPanel.add(this.fieldSeperatorField, constraints);
constraints.gridx = 1;
constraints.gridy = 0;
constraints.gridwidth = 3;
generalPanel.add(this.filenameField, constraints);

Any ideas where I'm getting it wrong ?

Thx in advance,

Joris
 
Ad

Advertisements

J

Joris Bleys

Have a look at the setHorizontalAlignment(int) method.

Dan.

Ok, I tried the method you suggested, but the problem seemed to be the
JTextField next to it was centered in its own field, so putting an anchor
on that field to the West solved it.

Thank you very much for your advice

George
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top