BoxLayout拉伸组件以适合父面板 [英] BoxLayout stretches component to fit parent panel

查看:112
本文介绍了BoxLayout拉伸组件以适合父面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我使用 BoxLayout JPanel 叠加在彼此之上( BoxLayout.Y_AXIS ),例如,如果我的父 JPanel 的高度为500像素,我将两个子面板添加到高度100像素。 BoxLayout 将它们拉伸,以便它们共同占据500px空间。有谁知道如何禁用此功能?

Hi I am using a BoxLayout to stack JPanels 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?

推荐答案

使用 GridBagLayout 。你可以更好地控制你的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拉伸组件以适合父面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆