BorderLayout - control height, but not width

I am relatively new to Java UI and would appreciate your help with the simple problem I have.

I have a JPanel type BorderLayout . The CENTER part contains a combo box.

When resizing an external frame, the panel changes its size (this is necessary), and the width of the combo box changes (this is also necessary). However, the height of the combobox also changes when the panel is resized. This is undesirable.

How can I make sure my combo box expands in width but not in height?

I also have a button in LINE_START . I would like this button not to stretch.

+4
source share
2 answers

Put a combo. in the NORTH panel, which is then added to the CENTER main BorderLayout . Do the same with the button.

+6
source

I would strongly suggest you use TableLayout as your personal favorite. Since you can arrange your elements as if they were in a table, without much hassle.

Read more about this here .

This link will lead you to the full site about it.

I’m afraid that this layout manager might be a bit dated, of course, the examples on his page, but it works fine even in Java version 1.7.

Take a look at an example. The option you should use to stretch the field (i.e., fill the free space) is TableLayout.FILL .

+5
source

Source: https://habr.com/ru/post/1411261/


All Articles