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/