删除JTable(Windows LaF)中的单元格编辑器边框 [英] Remove cell editor border in JTable (Windows LaF)

查看:198
本文介绍了删除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):

这篇关于删除JTable(Windows LaF)中的单元格编辑器边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆