Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

GridBagLayout is the layout you want to use if you need to align components and such. Read How to Use GridBagLayout.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top