在我的应用程序中,我有一个 2 列的 org.jdesktop.swingx.JXTable。两列都包含字符串数据。一列使用默认单元格编辑器 (org.jdesktop.swingx.JXTable.GenericEditor),另一列使用自定义单元格编辑器 (CustomCellEditor.java)。
在 Windows L&F 中,两个单元格呈现相同;然而,GTK L&F 存在细微差别,导致文本模糊。需要设置什么属性才能在 GTK 上正确呈现自定义编辑器?
private class CustomCellEditor extends DefaultCellEditor
{
public CustomCellEditor(int maxStringLength)
{
super(new JTextField()
((JTextField) editorComponent).setDocument(new CustomDocument(maxStringLength));
}
class CustomDocument extends PlainDocument
{
private int limit;
public CustomDocument(int limit)
{
super();
this.limit = limit;
}
@Override
public void insertString(int offset, String str, AttributeSet attr)
throws BadLocationException
{
//...
}
}
}
Windows 上的默认值:
Windows 上的自定义:
Ubuntu 上的默认值:
在 Ubuntu 上自定义:
最佳答案
我过去也遇到过同样的问题,但是使用 Nimbus L&F My issue
这样做就解决了
JTextField#setBorder( null )
在你的代码中
public CustomCellEditor(int maxStringLength)
{
super(new JTextField());
((JTextField) editorComponent).setDocument(new CustomDocument(maxStringLength));
((JTextField) editorComponent).setBorder(null); // cast may be not needed
}
关于java - JTable 单元格渲染跨平台差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17752693/