删除JTable(Windows LaF)中的单元格编辑器边框

问题描述:

我有一个基于JTextField的单元格编辑器,它带有这个难看的黑色边框(忽略左侧的插入符号):

I have a JTextField based cell editor that comes with this ugly black border (ignore the caret on the left):

是否可以删除它,使其看起来与此类似?

Is there a way to remove it so it looks similar to this?

创建表后,您可以尝试以下操作:

After creating the table you can try something like:

DefaultCellEditor editor = (DefaultCellEditor)table.getDefaultEditor(Object.class);
JTextField textField = (JTextField)editor.getComponent();
textField.setBorder( null );

以上方法无效,因为JTable使用GenericEditor,它是表的内部类,扩展了DefaultCellEditor并为该表添加了额外的功能.

The above approach won't work because the JTable uses a GenericEditor which is an inner class of the table that extend the DefaultCellEditor and adds extra functionality for the table.

添加的一项功能是管理边框:红色"表示错误,黑色"表示有效数据.因此,边框会不断被编辑器重置.

One piece of functionality added is to manager the Border: "red" for errors and "black" for valid data. So the border is continually being reset by the editor.

或者其他方法是这样的:

Or the other approach would be something like:

JTextField textField = new JTextField();
textField.setBorder( null );
DefaultCellEditor editor = new DefaultCellEditor( textField );
table.setDefaultEditor(Object.class, editor):