JTable自定义单元格渲染器焦点问题

发布于 2024-12-02 10:17:49 字数 569 浏览 1 评论 0原文

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

在此处输入图像描述

看起来不错。但问题是我们必须输入值并且必须按“ENTER”。在该图像中,我输入了密码,但没有按 Enter 键。所以如果我点击“保存并保存”关闭'按钮,它会显示密码字段为空的错误。

以前我只在 JTabbedPane 下使用过 JTextFields 和 JPasswordFields,效果很好。当我不得不添加越来越多的东西时,我把它改成了这样的表格。

现在我已经贴了一个标签,让人们知道他们应该按 ENTER 键。这不太好。另一个大问题。至少在 Nimbus 的外观和感觉中,我们知道该领域仍然是焦点。在Windows系统中,无论视野是否聚焦,都没有太大明显的区别。

在此处输入图像描述

当我单击“保存并保存”时,我需要用户名字段或密码字段来设置其值。关闭'按钮。请帮我。

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 image description here

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.

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.

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.

enter image description here

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尾戒 2024-12-09 10:17:49

所以你的问题是,你仍在编辑单元格。所以你必须停止编辑,然后单元格才会改变。

在您的按钮上,您可以获取正在编辑的单元格
TableCellEditor cellEditor = table.getCellEditor();
然后你可以停止编辑
if(cellEditor!=null){
cellEditor.stopCellEditing();
}

然后你可以保存该值

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.

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

污味仙女 2024-12-09 10:17:49

告诉表在失去焦点时自动提交:

table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

Tell the table to automatically commit when losing focus:

table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文