java添加两个按钮,java – 如何在boxLayout中的两个按钮之间添加一个空格?

如果要在组件之间具有空格,可以向一个或两个组件添加空边框,或插入不可见组件以提供空间。您可以在Box类的帮助下创建不可见组件。

因为你已经使用胶水没有成功(我怀疑为什么?),你可以尝试像刚性区域,

container.add(firstComponent);

container.add(Box.createRigidArea(new Dimension(5,0)));

container.add(secondComponent);

三个因素影响容器中可见组件之间的空间量:

>布局管理器

Some layout managers automatically put space between components; others do not. Some let you specify the amount of space between components. See the how-to page for each layout manager for information about spacing support.

>隐形部件

You can create lightweight components that perform no painting, but that can take up space in the GUI. Often, you use invisible components in containers controlled by BoxLayout. See 07002 for examples of using invisible components.

>空边框

No matter what the layout manager, you can affect the apparent amount of space between components by adding empty borders to components. The best candidates for empty borders are components that typically have no default border, such as panels and labels. Some other components might not work well with borders in some look-and-feel implementations, because of the way their painting code is implemented. For information about borders, see 07003 .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值