如何在Swing中的组件边框外添加边距? [英] How do I add a margin outside the border of a component in Swing?

查看:1248
本文介绍了如何在Swing中的组件边框外添加边距?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了多个涂有边框的组件。是否有任何简单的方法可以为组件添加边距,使边框不会彼此如此接近?

I use multiple components that has a border painted. Is there any easy way to add a margin to the component so that the borders aren't painted so close to eachother?

推荐答案

这通常使用您的布局管理器完成。例如,如果您使用 GridBagLayout ,则应在 GridBagConstraint上设置 insets 对象到所需的值。

This is typically done using your layout manager. For example, if you are using GridBagLayout, you would set insets on the GridBagConstraint object to the desired value.

另一种选择是使用 Box 对象并添加一个水平或垂直结构。请参见 javadoc for Box.createVerticalStrut(int width)和类似的 createHorizo​​ntalStrut

Another option is to use the Box object and add a horizontal or vertical struct. See javadoc for Box.createVerticalStrut( int width ) and the similar createHorizontalStrut.

这篇关于如何在Swing中的组件边框外添加边距?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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