I need suggestion for layout type for following task. I have a panel on which user will be able to add or remove some components (label or another panel), which are all same size. There will be specific number of components at same column (like 4 components per column) but the number of components in rows will depend on user. The distance between components will be fixed, right, left up top. I will link you the image of what i need... Thanks. link
Asked
Active
Viewed 30 times
0
-
2http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html – Maroun Oct 18 '14 at 21:16
-
Seems like GridLayout is a way to go, but when there is only 1 component (on start) it stretches my panel, how to avoid this? – Ђорђе Ђашић Oct 18 '14 at 21:20
1 Answers
0
I think you want a GridLayout, however I suggest using a third-party layout manager like MigLayout. For the case where you have empty cells, you can nest JComponents
within each other with different layout managers ( see this SO question). MigLayout
would be easier because it can simulate a GridLayout
while respecting the preferred size you set on your JComponents
, which allows you to have empty cells without the components stretching.