Java 如何设置 JLabel 的边距?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22384414/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I set the margin of a JLabel?
提问by joshreesjones
I have a JLabel
that I want to add a margin to. It looks like this:
我有一个JLabel
要添加边距的对象。它看起来像这样:
I read about setting an empty border with a certain thickness, but this would replace the current border. How can I add this margin?
我读到设置具有一定厚度的空边框,但这将替换当前边框。如何添加此边距?
采纳答案by Paul Samsotha
"I read about setting an empty border with a certain thickness, but this would replace the current border. How can I add this margin?"
“我读过关于设置具有一定厚度的空边框,但这将替换当前边框。我该如何添加此边距?”
See CompoundBorder
见复合边框
A composite Border class used to compose two Border objects into a single border by nesting an inside Border object within the insets of an outside Border object. For example, this class may be used to add blank margin space to a component with an existing decorative border:
一个复合 Border 类,用于通过将内部 Border 对象嵌套在外部 Border 对象的插入中来将两个 Border 对象组合成单个边框。例如,此类可用于向具有现有装饰边框的组件添加空白边距空间:
Border border = comp.getBorder();
Border margin = new EmptyBorder(10,10,10,10);
comp.setBorder(new CompoundBorder(border, margin));
Also see EmptyBorder
另见空边框