简体   繁体   中英

BorderLayout - Control height but not width

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

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

As the outer frame is resized, the panel resizes (this is desired) and the width of the combo box changes (this is desired too). However, the height of the combobox is also changing as the panel is resized. This is not desired.

How can I ensure that 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 at all.

Put the combo. into the NORTH of a panel that is then added to the CENTER of the main BorderLayout . Do the same with the button.

I would strongly suggest for you to use TableLayout my personal favourite. Since you can layout your elements as if they were in a table, without much hassle.

You can read more about it here.

This link takes you to a full site about it.

I am afraid this layout manager might be slightly outdated, certainly the examples on its page are, but it works great even in 1.7 version of Java .

Look at the example there. The option you would use to make the box to stretch (ie fill the available space) is TableLayout.FILL .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM