java - 如何设置 JLabel 的边距?

标签 java swing

我有一个 JLabel,我想为其添加边距。它看起来像这样:

enter image description here

我读到有关设置具有一定厚度的空边框,但这会替换当前边框。我怎样才能添加这个 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?"

参见 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 = 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/

相关文章:

java - 在 Java 中解密 C# AES 加密文本

java - 即使凭据为真,Spring Boot Security 也会在 API 调用上抛出 401 身份验证错误

java - 选择 JRadioButton 时如何设置不可编辑的 JTable 单元格?

java - JLabels 放置在彼此之上

java - Java中的MongoDB,如何从另一个文档中包含的数组中检索neSTLed文档?

java - 确保始终从 Spring 应用程序的缓存中检索数据

java - 在 fragment 中检查已更改监听器的 radio 组

Java-LAF : How to create Decoration using Synth-XML?

java - B 样条基函数似乎产生不正确的值

java - GUI 的标签问题