[英]Start Editing a cell in JTable automaically
I am developing a restaurant billing system. 我正在开发一个餐厅计费系统。
So here is the order panel interface 这是订单面板界面
So now when i click on the menuTable the item code automatically gets added to kotTable 所以现在当我单击menuTable时,商品代码会自动添加到kotTable中
and when i press "Q" the focus shifts to quantity column in kotTable. 当我按“ Q”时,焦点将移至kotTable中的“数量”列。
` `
private void menuTableKeyTyped(java.awt.event.KeyEvent evt)
{
if(evt.getKeyChar()=='Q') {
kotTable.editCellAt(i-1,2);
}
} `
The problem is The cell doesnt start editing automatically. 问题是该单元格不会自动开始编辑。 I need to click on that cell and then the editing starts. 我需要单击该单元格,然后开始编辑。 i tried using DefaultCellEditor , getInputMap() and many other. 我尝试使用DefaultCellEditor,getInputMap()和许多其他方法。 But I am bit confused and the problem is not solved.. Thanx 但是我有点困惑,问题没有解决。
Using a key binding , you can map the Q key to the table's "startEditing"
action. 使用键绑定 ,可以将Q键映射到表的"startEditing"
操作。 More examples may be found here . 在这里可以找到更多示例。
table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_Q, 0), "startEditing");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.