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?

有帮助吗?

解决方案

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.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top