java - JTable 单元格渲染跨平台差异

标签 java swing cross-platform swingx tablecelleditor

在我的应用程序中,我有一个 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 上的默认值:

enter image description here

Windows 上的自定义:

enter image description here

Ubuntu 上的默认值:

enter image description here

在 Ubuntu 上自定义:

enter image description here

最佳答案

我过去也遇到过同样的问题,但是使用 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/

相关文章:

用于迭代和 HTML 实现的 Javascript 函数

java - 在java中使用JPanel时,如何将一个类中的用户输入数据显示到另一个类中

java - 当鼠标放在 JButton 上时更改 JButton 背景颜色(不是鼠标悬停)

java - 什么时候需要在 swing 组件上调用 revalidate() 以使其刷新,什么时候不需要?

ms-word - docx/doc/rtf 与轻量级标记之间的转换

java - 从泛型方法调用重载方法

java - 如何从byteArray写入BitSet? (我们需要java 1.7)

scripting - 实用程序脚本使用什么脚本语言?

android - 如何在 iPhone 上运行 Ubuntu 操作系统的 React Native 应用程序

java - Spring Boot 测试和 Jackson - 在测试中从上下文设置 (application.yml) 获取 ObjectMapper 的实例,无需开销配置