I have a situation where I have a load of buttons and a textfield (with label). When the user has the window maximized I want the buttons all in a line to save vertical space, however if the user shrinks the width of the window so the buttons no longer fit, I would like them to do the default Flowlayout, and go onto annother line. This works fine, except I need scroll pane for when the window gets so small as to start obscuring the text field.
I think this diagram shows what I need better than I can explain:
http://img441.imageshack.us/img441/1460/54793673.png
Here is an example showing my "problem"
import java.awt.*;
import javax.swing.*;
public class Test {
public static void main(String[] args) {
JFrame f = new JFrame();
JPanel parentPanel = new JPanel();
parentPanel.setLayout(new GridLayout(2,1));
JPanel buttonPanel = new JPanel();
buttonPanel.add(new JButton("some"));
buttonPanel.add(new JButton("large"));
buttonPanel.add(new JButton("ammounts"));
buttonPanel.add(new JButton("of"));
buttonPanel.add(new JButton("buttons"));
buttonPanel.add(new JButton("!!!"));
parentPanel.add(new JLabel("some short label, but still needs to be seen"));
parentPanel.add(buttonPanel);
//if the scroll pane isnt there it almost does what i want
f.add(new JScrollPane(parentPanel));
f.pack();
f.setVisible(true);
}
}
Thanks for any help