Вопрос

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