2

在我的应用程序中,我有一个 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 上自定义:

在此处输入图像描述

4

1 回答 1

2

我过去有同样的问题,但是 Nimbus L&F 我的问题

通过这样做解决

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
    }
于 2013-07-19T18:08:19.907 回答