I'm using a 3x2 grid layout in a JPanel. The left column are labels
and the right columns are JTextFields. These text fields contain
values that are only a few chars long (numbers generally). My problem
is that the text fields are filling up the whole block on the grid but
I'd like them to be of a fixed size, so they won't change if the
window is resized.
Is there a simple way of doing this? Or, failing that, a complicated
way...
thanks for your help.
alan
Lee Weiner - 29 Dec 2003 18:40 GMT
>I'm using a 3x2 grid layout in a JPanel. The left column are labels
>and the right columns are JTextFields. These text fields contain
[quoted text clipped - 5 lines]
>Is there a simple way of doing this? Or, failing that, a complicated
>way...
The simple way is to put JPanels (with default FlowLayout) into the cells in
the right column and add the JTextFields to the panels.
Lee Weiner
lee AT leeweiner DOT org
Karsten Lentzsch - 29 Dec 2003 19:28 GMT
> I'm using a 3x2 grid layout in a JPanel. The left column are labels
> and the right columns are JTextFields. These text fields contain
[quoted text clipped - 4 lines]
>
> Is there a simple way of doing this? [...]
If you want the text fields use individual width
then set the column property or use the constructor
that accepts the columns and let the layout manager
honor the text fields preferred size.
In the Forms layout system you could write:
FormLayout layout = new FormLayout(
"pref, 4dlu, left:pref, 3dlu, left:pref");
DefaultFormBuilder builder = new DefaultFormBuilder(layout);
builder.setDefaultDialogBorder();
builder.append("Label1", field11, field12);
builder.append("Label2", field21, field22);
return builder.getPanel();
The Forms open source project is hosted at
JavaDesktop.org, where you can download the
library, sources, a tutorial and tutorial sources,
see http://forms.dev.java.net/
You can find screenshots and more demos at
http://www.jgoodies.com/freeware/forms/
Best regards,
Karsten