I have two panels which are using flow layouts. These panels have same number of components (labels and text boxes). How do I align them?
Asked
Active
Viewed 94 times
0
-
1you might consider using a third party LayoutManager (f.i. one of the big three MigLayout, FormLayout, DesignGridLayout) - personally, I think that none of the core managers fully fit real world usage: Spring- and GroupLayout designed for usage with visual builders and GridBagLayout overcomplex without being really powerful enough
:) – kleopatra Mar 25 '13 at 08:32
3 Answers
2
Layout managers don't communicate with one another that way. You can't use two separate FlowLayouts unless the components are all the same size.
You might be able to use a SpringLayout. Or more complex layouts would be the GridBagLayout and GroupLayout.
Check out the Swing tutorial on Using Layout Managers for working examples to decide which you would like to use.

camickr
- 321,443
- 19
- 166
- 288
1
I couldn't make this to work only, when I have hardcoded some stuff, like sizes.
I would recommend to switch to a GridBagLayout instead at least.
-
WOuld getting the Hgap and VGap from Panel1's layout and Seting to Panel2's layout work? – vasu1486 Mar 24 '13 at 20:01
-
1No, because the gap is the same for every component. Its the preferred size of the component that matters. – camickr Mar 24 '13 at 20:05
-
with two panel and each FlowLayout isn't a best practice, believe me. GridLayout, GridBagLayout, Absolute Layout, FormLayout you will need. I have used SpringLayout too, but that component isn't free and is third party – Mar 24 '13 at 20:05
-
0
GridBagLayout is the layout you want to use if you need to align components and such. Read How to Use GridBagLayout.

jessechk
- 450
- 5
- 15