我有一个 JLabel
,我想为其添加边距。它看起来像这样:
我读到有关设置具有一定厚度的空边框,但这会替换当前边框。我怎样才能添加这个 margin ?
最佳答案
"I read about setting an empty border with a certain thickness, but this would replace the current border. How can I add this margin?"
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 = comp.getBorder();
Border margin = new EmptyBorder(10,10,10,10);
comp.setBorder(new CompoundBorder(border, margin));
另见 EmptyBorder
关于java - 如何设置 JLabel 的边距?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22384414/