JTable-通过按Tab键使单元格进入“编辑"模式 [英] JTable - Getting a cell into Edit mode on pressing Tab

查看:215
本文介绍了JTable-通过按Tab键使单元格进入“编辑"模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能有一个微不足道的解决方案,但是我束手无策,所以希望有人能帮忙.

This is possibly has a trivial solution, but I am at the end of my tether so I hope somebody can help out.

我使用一个JTable,它具有用于一组列的自定义渲染器和自定义编辑器.
渲染器使用JLabel组件,而编辑器使用JSpinner组件.
我们的用户希望能够在列中输入值,然后按TAB或ENTER键移动到表中的下一个可编辑单元格.
如果我正确理解,这是JTable的默认行为.

I use a JTable which has a custom renderer and a custom editor for a set of columns.
The renderer uses a JLabel component and the editor uses a JSpinner component.
Our users want to be able to enter values in a column, and then press TAB or ENTER to move to the next editable cell in the table.
If I understand correctly, this is the default behaviour for a JTable.

但是,这对我来说似乎无法正常工作.在用户单击单元格之前,仅显示JLabel.
仅当用户双击单元格时,才会显示JSpinner(即CellEditor).因此,看起来该单元格仅在MouseEvents上才进入编辑"模式,而在其具有焦点时却没有.

However, this doesn't seem to work correctly for me. Until the user clicks on the cell, only the JLabel is displayed.
The JSpinner (i.e. CellEditor) is only displayed when a user double clicks on the cell. So, it looks like the cell is going into "edit" mode only on MouseEvents, but not when it has focus.

如何使单元格一获得焦点就进入编辑模式?

How do I get the cell to go into edit mode as soon as it has focus?

推荐答案

您可以通过编程实现此目的,您只需侦听单元格上的焦点事件,允许的焦点和编辑,然后开始编辑即可.

You can achieve this programatically, you simply listen to the focus events on the cell, on focus and editing allowed, start editing.

有关此 查看全文

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