使用java DefaultCellEditor在JTable中获取正确的编辑行为 [英] Get correct editing behaviour in JTable using java DefaultCellEditor

查看:189
本文介绍了使用java DefaultCellEditor在JTable中获取正确的编辑行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以通过单击它来进入Jtable中的单元格,或者使用光标键/选项卡进入它。使用defaultCellEditor和JtextField如果使用光标键,插入符号将放在现有文本字段的末尾,而如果双击该字段,则会突出显示最后一个单词。

You can go into a cell in a Jtable either by clicking on it, or by going into it using cursor keys/tabs. With defaultCellEditor and a JtextField if you go in using cursor keys the caret is put at the end of the existing text field, whereas if you double click the field it will highlight the last word.

电子表格似乎与双重克隆相同(如Open Office Calc),但如果您选择进入字段并开始编辑,则字段将被清除,按下的第一个字符成为字段中的第一个字符,依此类推。

Whereas spreadsheets seem to work (such as Open Office Calc) the same way for a double clcking, but if you tab into the field and start editing the field is cleared and the first character pressed becomes the first value in the field and so on.

我希望我的应用程序的工作方式与电子表格相同。通过继承DefaultCellEditor并添加

I want my app to work the same way as the spreadsheet. By subclassing DefaultCellEditor and adding

final Caret caret = editField.getCaret();
    caret.setDot(0);
    editField.setText("");

我可以在标签时按照我想要的方式工作,但它也会在双击时清除字段我不想要。

I can get it to work how I want when tabbing but it also clears the field on double click which I dont want.

那么请问如何确定键盘或鼠标是否触发了单元格编辑?

So please how can I determine if cell editing has been triggered by keyboard or mouse ?

推荐答案

也会覆盖isCellEditable(EventObject anEvent)方法。

override the isCellEditable(EventObject anEvent) method too.

这样您就可以捕获将要触发的事件(或表格版本并以您想要的方式行事

So that you can capture the event which is going to trigger (or not) the table edition and act the way you want

这篇关于使用java DefaultCellEditor在JTable中获取正确的编辑行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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