JTable自定义单元格渲染器焦点问题 [英] JTable custom cell renderer focus problem

查看:50
本文介绍了JTable自定义单元格渲染器焦点问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张这样的桌子.第二列使用JTextField渲染器,第三列使用基于JPasswordField的渲染器和编辑器.

I have a table like this. The second column uses a JTextField renderer and the third column uses a JPasswordField based renderer and editor.

看起来不错.但是问题是我们必须键入值,并且必须按"ENTER".在该图中,我输入了密码,但是没有按Enter键.因此,如果我单击保存并保存",关闭"按钮,它会提示我密码字段为空的错误.

Looks good. But the problem is We have to type the values and must hit "ENTER". In that image, I have typed my password but didn't hit Enter. So If I click the 'Save & Close' button, it'll show me an error that password field is empty.

以前,我仅在JTabbedPane下使用JTextFields和JPasswordFields,并且效果很好.当我不得不添加越来越多的东西时,我将其更改为这样的表.

Previously I have used only JTextFields and JPasswordFields under JTabbedPane and it worked well. When I had to add more and more stuff, I changed it to a table like this.

现在,我已经贴了一个标签,让人们知道他们应该按ENTER键.另一个大问题. Nimbus的外观和感觉,我们认为该领域仍然是重点.在Windows系统外观中,该字段是否聚焦没有太大的可见差异.

For now I have put a label to let people know that they should hit the ENTER.. This is not nice. Another big issue. Atleast in Nimbus Look and feel, we get an idea that that field is still in focus. In Windows system look, there's not much visible difference whether the field is focused or not.

当我单击保存并删除"时,我需要用户名字段或密码字段来设置其值.关闭"按钮.请帮助我.

I need the Username field or password field to set it's value when I click 'Save & Close' button. Please help me.

推荐答案

所以您的问题是,您仍在编辑单元格.因此,您必须停止编辑,然后才能更改单元格.

So your problem is, that you are still editing the cell. So you have to stop the editing and then the cell will be changed.

您可以通过按钮获取正在使用其进行编辑的单元格
TableCellEditor cellEditor = table.getCellEditor();
然后您可以使用
停止编辑 if(cellEditor!=null){
cellEditor.stopCellEditing();
}

然后您可以保存值

At your button you can get the cell who is being edited with
TableCellEditor cellEditor = table.getCellEditor();
then you can stop the editing with
if(cellEditor!=null){
cellEditor.stopCellEditing();
}

and then you can save the value

这篇关于JTable自定义单元格渲染器焦点问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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