问题描述
您好我使用 BoxLayout
将 JPanel
叠加在彼此之上( BoxLayout.Y_AXIS
),例如,如果我的父 JPanel
的高度为500像素,我将两个子面板添加到高度100像素。 BoxLayout
将它们拉伸,以便它们共同占据500px空间。有谁知道如何禁用此功能?
Hi I am using a BoxLayout
to stack JPanel
s on top of each other (BoxLayout.Y_AXIS
), for example if my parent JPanel
is of height 500 pixels and I add two child panels to it both of height 100 pixels. The BoxLayout
stretches them so that together they occupy the the 500px space. Does anyone know how to disable this feature?
推荐答案
使用。你可以更好地控制你的UI。
Use GridBagLayout instead. You have much more control over your UI.
但是如果你想要使用BoxLayout,并且不希望它们伸展,你可以使用,如刚性区域,胶水和填充物。
But if you want to use BoxLayout still, and don't want them to stretch, you can check out using invisible component fillers like rigid areas, glue and fillers.
这篇关于BoxLayout拉伸组件以适合父面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!