How to set the component size with GridLayout? Is there a better way?
- by Blackbam
Hello guys,
I am working on a larger GUI with Java and I am becoming angry on Layout Managers.
I have a "Settings-Panel" with a variable number of JComponents in it (Labels, Buttons, JSpinners, JSliders,...). I just want the following:
JLabel <- JComponent
JLabel <- JComponent
JLabel <- JComponent
...
My Panel has a size of 500px, so that there is enough space for a lot of components. Unfortunatly the GridLayout always stretches the size of the Components to the whole Panel, even if I set a MaximumSize for every component. It looks stupid if there are only two buttons each with a height of 250px.
I tried flow Layout, but i cannot figure out a way to make new lines properly. I tried BoxLayout.Y_AXIS, but the Components are always centered, and Label and Component are not in the same line.
Does anybody know a good and short way with LayoutManagers to handle this properly?