Frage

I have created a program in which I display result-filtering options on the side of my Swing window, however by default they appear horizontally next to one another, which wastes the space I have allotted in my BorderLayout's WEST side. Is there anything I can pass in my constructor or add-statement that will stack these up? Here's my relevant code in a class that extends JFrame:

box1 = new JCheckBox("Points");box2 = new JCheckBox("Bleh");
pane = new JPanel();
pane.add(box1);pane.add(box2);
add(pane, BorderLayout.WEST); 

So this is quite simple, but when displayed they show side-by-side, and that's what I am looking to change. Any help will be greatly appreciated. If I missed a good source of research info, please pass it along.

War es hilfreich?

Lösung

Use GridLayout with n rows and one column for pane, where n is the number of checkboxes

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top