BoxLayout « JTextField « Java Swing Q&A





1. How do I keep JTextFields in a Java Swing BoxLayout from expanding?    stackoverflow.com

I have a JPanel that looks something like this:

JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

...

panel.add(jTextField1);
panel.add(Box.createVerticalStrut(10));
panel.add(jButton1);

panel.add(Box.createVerticalStrut(30));

panel.add(jTextField2);
panel.add(Box.createVerticalStrut(10));
panel.add(jButton2);

... //etc.
My problem is that the JTextFields become huge vertically. I want them to only be high ...

2. Problem with BoxLayout and JTextField    coderanch.com