2013-07-19 53 views
2

在我的应用程序中,我有一个2列org.jdesktop.swingx.JXTable。两列都包含字符串数据。一列使用默认单元格编辑器(org.jdesktop.swingx.JXTable.GenericEditor),另一列使用自定义单元格编辑器(CustomCellEditor.java)。JTable单元格渲染差异跨平台

与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上:在Ubuntu

enter image description here

默认:

enter image description here

自定义在Ubuntu:

enter image description here

+0

试着把'setBorder(null)' – nachokk

回答

2

我有同样的问题,在过去但雨云大号&˚FMy 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 
    } 
+0

正是需要的! – javacavaj

+0

@javacavaj是否奏效? – nachokk

+0

是的,它的工作。谢谢! – javacavaj