JTextField layout control

From: steven (yu271637_at_yorku.ca)
Date: 08/25/04


Date: 25 Aug 2004 13:31:37 -0700

Hi,

I try to arrange several JTextField components in Box container. Below is my code.

private static void addTextField(String text, Container container) {
            Box box = Box.createVerticalBox();
            JLabel label = new JLabel(text);
            JPanel panel = new JPanel();
            JTextField textfd = new JTextField(10);
            panel.add(textfd);
            label.setLabelFor(textfd);
            box.add(label);
            box.add(panel);
        container.add(box);
    }
    .
    .
    .
Box box = Box.createVerticalBox();
for(int i = 0; i < 3; i++){
   addTextField(" test " + i, box);
}

The result is the JTextField is far away from the label. like the demo below:
        
 test0
                                      ----------
                                      | |
                                      ----------

I have no idea how to control the size of the JTextField and the location.

Any suggestion?

Steven



Relevant Pages

  • Re: KeyListener not working in 1.4 - solved
    ... something like a JTextField or JButton to the container. ... I can swear ... Let the base container class implement ActionListener and ... ...
    (comp.lang.java.gui)
  • Re: JOptionPane focus
    ... is it possible to set initial focus to the JTextField? ... private static void createAndShowGUI() { ... int choice = JOptionPane.showConfirmDialog( ...
    (comp.lang.java.gui)