java - 删除 TitledBorder 周围的间距

标签 java swing titled-border

javax.swing.border.TitledBorder 在边框边缘引入了 2 个像素的间距。这非常烦人,因为它破坏了与周围组件的对齐。

如何消除这个间距?

我正在寻找适合任何外观和感觉的解决方案。

最佳答案

不幸的是,这个边缘宽度在 TitledBorder 类中被硬编码。因此您无法删除此间距。

public class TitledBorder extends AbstractBorder
{
    //...

    // Space between the border and the component's edge
    static protected final int EDGE_SPACING = 2;
}

但是您可以尝试扩展此类(覆盖方法“void PaintBorder(Component, Graphics, int, int, int, int)”或可能是“Insets getBorderInsets(Component, Insets)”)或实现您自己的边框从头开始。

关于java - 删除 TitledBorder 周围的间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7906216/

相关文章:

java - 是否可以将 GROUP BY 与绑定(bind)变量一起使用?

java - Stream.toList() 会比 Collectors.toList() 表现得更好吗

java - 如何在 ComboBox 上使用 ActionListener 为变量赋值

java - 使 TitledBorder 标题可编辑

java - 不知道如何使用 SetBorder

java - 使用 RandomAccessFile 通过 writeUTF() 读取空间

java - QueryDSL 不返回对象

java swing- 可以在应用程序图标/标题旁边添加 JLabel 吗?

java - 调整子组件 Swing 的大小

android - 如何在 Android 中创建带标题的边框?