English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I'm trying to make a form on a Java Applet, however I'm finding it very difficult to get the text labels and corresponding textboxes to align themselves one per line. GridLayout is what I need to use (I think) but when I use that, it adjusts my textbox components to fill the entire region of their alloted Grid cell -- not what I want. There must be an easy way to make a simple form on an Applet? Any help appreciated.

2007-08-06 11:42:38 · 1 answers · asked by Tigian 1 in Computers & Internet Programming & Design

1 answers

I'd recommend you switch to a GridBagLayout. This will let you specify fill conditions (vertical, horizontal, both, none) on each component you insert, and anchoring (which edge of the cell for components that don't fill it completely).

It's slightly more complex than GridLayout, but gives you the control over sizing that you want.

Here's a snippet of some of my code that uses GridBagLayout:

=======================
jOptionPanel = new JPanel();
jOptionPanel.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();

gbc.fill = gbc.NONE;
gbc.gridx = 0;
gbc.gridy = 0;
gbc.weightx = 0.0;
gbc.weighty = 0.0;
gbc.insets = INSETS;
gbc.anchor = gbc.EAST;
jOptionPanel.add( getBatchIdLabel(), gbc);

gbc.gridy = 1;
jOptionPanel.add( getEnableGlDeletionLabel(), gbc);

gbc.gridy = 2;
gbc.anchor = gbc.CENTER;
jOptionPanel.add( getDoTransformButton(), gbc);

gbc.fill = gbc.HORIZONTAL;
gbc.gridx = 1;
gbc.gridy = 0;
gbc.anchor = gbc.WEST;
jOptionPanel.add( getBatchIdTextField(), gbc);

gbc.gridy = 1;
jOptionPanel.add( getEnableGlDeletionCheckBox(), gbc);
=======================

2007-08-06 11:47:27 · answer #1 · answered by McFate 7 · 0 0

fedest.com, questions and answers