I'm trying to add buttons to a scroll pane, I need the buttons to be of a fixed size, so that they won't change size if more buttons are added etc.
Here is my code so far
public class Menu extends JPanel
{
JButton a = new JButton("test");
JButton b = new JButton("test1");
JButton c = new JButton("test3");
JButton d = new JButton("test4");
JButton e = new JButton("test5");
JButton f = new JButton("test6");
JButton g = new JButton("test7");
JButton h = new JButton("test8");
Menu()
{
JPanel me = new JPanel();
me.setLayout(new GridLayout(0,2));
me.add(a);
me.add(b);
me.add(c);
me.add(d);
me.add(e);
me.add(f);
me.add(g);
me.add(h);
JFrame frame = new JFrame();
JScrollPane spane = new JScrollPane(me);
spane.setPreferredSize(new Dimension(180,500));
add(spane);
frame.add(this);
}
}
This doesn't work because the buttons size will be adjusted to fit the size of the pane.
I need to have it to that if there are too many buttons to show, then a scroll bar will be shown.
Any ideas?
Thanks