问题描述
这可能有一个微不足道的解决方案,但是我束手无策,所以希望有人能帮忙.
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.
这篇关于JTable-通过按Tab键使单元格进入“编辑"模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!