Hi, anstatt BoxLayout, verwende ich JFormattedTextField um die paare "JLabels und JTextField" aufzustellen.
There is one bad display problem, the vertical misalignment betw JLables and their corresponding JTextFields.
Here is the code longish stub code:
Yes it works, bar the alignment problem.
Dar ich auf eine Antwort hoffen dieses mal? Tja!
TIA
There is one bad display problem, the vertical misalignment betw JLables and their corresponding JTextFields.
Here is the code longish stub code:
Code:
public class LayoutTest8 extends JApplet implements AdjustmentListener
{ ...java...
private JLabel lblName, lblAddr1, lblAddr2, lblCity, lblZip, lblCountry;
private JFormattedTextField fldName, fldAddr1, fldAddr2, fldCity, fldZip, fldCountry;
private static String strName = "Name: ";
private static String strAddr1 = "Address: ";
private static String strAddr2 = "Address: ";
private static String strCity = "City: ";
private static String strZip = "Zip Code: ";
private static String strCountry = "Country: ";
private NumberFormat pctFormat;
private MessageFormat msgFormat;
public void init()
{
setBackground(Color.lightGray);
Container contentPane = getContentPane();
JPanel px = new JPanel();
px.setLayout(new GridLayout(5,2));
...java...
JPanel p9 = new JPanel();
// p9.setLayout(new BoxLayout(p9, BoxLayout.Y_AXIS));
// create labels:
lblName = new JLabel(strName);
lblAddr1 = new JLabel(strAddr1);
lblAddr2 = new JLabel(strAddr2);
lblCity = new JLabel(strCity);
lblZip = new JLabel(strZip);
lblCountry = new JLabel(strCountry);
// create text fields:
fldName = new JFormattedTextField(msgFormat);
fldName.setColumns(20);
fldName.setEditable(false);
fldAddr1 = new JFormattedTextField(msgFormat);
fldAddr1.setColumns(20);
fldAddr1.setEditable(false);
fldAddr2 = new JFormattedTextField(msgFormat);
fldAddr2.setColumns(20);
fldAddr2.setEditable(false);
fldCity = new JFormattedTextField(msgFormat);
fldCity.setColumns(20);
fldCity.setEditable(false);
fldZip = new JFormattedTextField(msgFormat);
fldZip.setColumns(20);
fldZip.setEditable(false);
fldCountry = new JFormattedTextField(msgFormat);
fldCountry.setColumns(20);
fldCountry.setEditable(false);
// Accessibility : build pairs of labels + textfields
lblName.setLabelFor(fldName);
lblAddr1.setLabelFor(fldAddr1);
lblAddr2.setLabelFor(fldAddr2);
lblCity.setLabelFor(fldCity);
lblZip.setLabelFor(fldZip);
lblCountry.setLabelFor(fldZip);
// put pairs of label and text into their respective grid...
JPanel p9_left = new JPanel(new GridLayout(0,1));
p9_left.add(lblName);
p9_left.add(lblAddr1);
p9_left.add(lblAddr2);
p9_left.add(lblCity);
p9_left.add(lblZip);
p9_left.add(lblCountry);
JPanel p9_right = new JPanel(new GridLayout(0,1));
p9_right.setBackground(Color.WHITE);
p9_right.add(fldName);
p9_right.add(fldAddr1);
p9_right.add(fldAddr2);
p9_right.add(fldCity);
p9_right.add(fldZip);
p9_right.add(fldCountry);
p9.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
p9.add(p9_left,BorderLayout.CENTER);
p9.add(p9_right,BorderLayout.LINE_END);
px.add(p9);
Yes it works, bar the alignment problem.
Dar ich auf eine Antwort hoffen dieses mal? Tja!
TIA