本文介绍了如何使BoxLayout表现为垂直FlowLayout?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FlowLayout 从右侧执行压力,因此所有组件都试图获取最小宽度。相反, BoxLayout 尝试传播所有组件以填充空间的整个高度。

FlowLayout performs "pressure" from the right, so as all components are trying to take their minimal widths. Contrary, BoxLayout tries to spread all components to fill entire height of the space.

我可以添加一些填充物作为最后一个组件或什么使所有组件在 BoxLayout 中具有最小高度?

Can I add some filler as last component or something to make all components have minimal heights in BoxLayout?

推荐答案

你可以使用Box.createGlue(),它返回一个占用BoxLayout所需空间的组件。将它添加到垂直BoxLayout的底部会将其他组件添加到顶部。

You could use Box.createGlue(), which returns a component that takes up as much space as the BoxLayout will give it. Adding it to the bottom of a vertical BoxLayout will scrunch the other components to the top.

您也可以使用嵌套布局。

You could also use nested layouts.

这篇关于如何使BoxLayout表现为垂直FlowLayout?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 00:43