G
Guest
Gast
Hi, all.
I've tried this BoxLayout with PAGE_AXIS and X_AXIS alignment, it works, but there is this big gap between the components vertically. The components are self-defined and consists a pair of JLabel and JTextArea.
How do I pack the components tighter vertically i.e. along the Y-Axis ?
TIA
Here is the stub code for BoxLayout:
And here is the helper-class for the JLabel and JTextArea pair, called by the aforementioned code to insert the pair into the BoxLayout.
I've tried this BoxLayout with PAGE_AXIS and X_AXIS alignment, it works, but there is this big gap between the components vertically. The components are self-defined and consists a pair of JLabel and JTextArea.
How do I pack the components tighter vertically i.e. along the Y-Axis ?
TIA
Here is the stub code for BoxLayout:
Code:
public class LayoutTest8 extends JApplet implements AdjustmentListener
{ LabeledTextField lblName, lblAddr1, lblAddr2, lblCity;
public void init()
{ setBackground(Color.lightGray);
Container contentPane = getContentPane();
JPanel px = new JPanel();
...java...
JPanel p9 = new JPanel();
p9.setLayout(new BoxLayout(p9, BoxLayout.Y_AXIS));
p9.setBorder(BorderFactory.createLineBorder(Color.RED));
lblName = new LabeledTextField("Name", "Inside a BoxLayout");
lblAddr1 = new LabeledTextField("Address", "PAGE_AXIS orientation");
lblAddr2 = new LabeledTextField("Address", "PAGE_AXIS orientation");
lblCity = new LabeledTextField("City", "PAGE_AXIS orientation");
p9.add(lblName);
p9.add(lblAddr1);
p9.add(lblAddr2);
p9.add(lblCity);
px.add(p9);
contentPane.add(px);
...java...
Code:
public class LabeledTextField extends JPanel
{ private JLabel lbl;
private JTextField txtFld;
public LabeledTextField(String lblString,
Font lblFont,
int txtFieldSize,
Font txtFont)
{ setLayout(new FlowLayout(FlowLayout.LEFT));
lbl = new JLabel(lblString, JLabel.RIGHT);
if (lblFont != null) {lbl.setFont(lblFont);}
add(lbl);
txtFld = new JTextField(txtFieldSize);
if (txtFont != null) {txtFld.setFont(txtFont);}
add(txtFld);
}
public LabeledTextField(String lblString, String txtFieldString)
{ this(lblString, null, txtFieldString, txtFieldString.length(), null);
}
public LabeledTextField(String lblString, int txtFieldSize)
{ this(lblString, null, txtFieldSize, null);
}
public LabeledTextField(String lblString,
Font lblFont,
String txtFieldString,
int txtFieldSize,
Font txtFont)
{ this(lblString, lblFont, txtFieldSize, txtFont);
txtFld.setText(txtFieldString);
}
public JLabel getLabel() {return(lbl);}
public JTextField getTextField() {return(txtFld);}
}