简体   繁体   English

BorderLayout - 控制高度但不是宽度

[英]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. 我对Java UI相对较新,感谢您对我所遇到的一个简单问题的帮助。

I have a JPanel of type BorderLayout . 我有一个BorderLayout类型的JPanel The CENTER part contains a combo box. CENTER部分包含一个组合框。

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 . 我在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 . 进入面板的NORTH ,然后将其添加到主BorderLayoutCENTER中。 Do the same with the button. 使用按钮执行相同操作。

I would strongly suggest for you to use TableLayout my personal favourite. 我强烈建议您使用我个人最喜欢的TableLayout。 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 . 我担心这个布局管理器可能会稍微过时,其页面上的示例肯定是,但它甚至在1.7版本的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 . TableLayout.FILL是用于使框伸展(即填充可用空间)的选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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