简体   繁体   English

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

[英]Remove cell editor border in JTable (Windows LaF)

I have a JTextField based cell editor that comes with this ugly black border (ignore the caret on the left): 我有一个基于JTextField的单元格编辑器,它带有这个难看的黑色边框(忽略左侧的插入号):

在此处输入图片说明

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 );

Edit: 编辑:

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. 上面的方法行不通,因为JTable使用GenericEditor ,它是表的内部类,扩展了DefaultCellEditor并为表添加了额外的功能。

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):

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM