Search code examples
javaswingjpanellayout-managerflowlayout

Aligning components on two panels which are using flow layouts


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?


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.