Java GUI 垂直对齐
所以,我有 2 个不同高度的 JPanel。我想将它们垂直对齐到顶部。我应该使用什么类型的容器以及如何添加它们,以便它们都与顶部对齐,不以任何方式拉伸并且它们不是固定的(例如,如果我更改一个容器的大小并且它变得比另一个更大)一,我也不应该修改布局)
So, I have 2 JPanels of different Height. I want to vertical align them both to the top. What type of container should I use and how should I add them so they are both aligned to the top, not stretched in any way and they are not fixed (as in, if I change the size of one and it becomes bigger than the other one, I shouldn't modify the layout as well)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
老实说,我不知道我是否完全理解您的需求,无论如何尝试看看 BoxLayout。它非常灵活,可以嵌套垂直和水平 BoxLayout,并且通过使用胶水和刚性区域,您可以创建非常漂亮的 GUI,当框架改变尺寸时,组件会自动调整大小。
这是一个示例,但您可以在网络中搜索找到很多其他示例。
Honestly, I don't know if I completely understand what are your needs, anyway try to look at BoxLayout. It's very flexible and nesting vertical and horizontal BoxLayout, and with the use of glues and rigid area, you could create very nice GUI, which components resize automatically, when the frame change dimension.
Here's an example, but you can find a lot of others searching in the web.