开始编辑JTable Cell时选择所有数据 [英] Select all data when start editing JTable Cell

查看:107
本文介绍了开始编辑JTable Cell时选择所有数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个像Excel一样工作的表。这意味着,当用户开始将数据插入单元格时,内容将被选中并通过插入的新数据进行更改。

I'm trying to make a table that works like Excel. Meaning, when a user starts to insert data into the cells the content into them is selected and changed by the new data inserted.

推荐答案

您可以为表创建自定义TableCellEditor。这个类将有一个 TextField 的实例变量,让我们称之为 textField 。然后 getTableCellEditorComponent 方法可能如下所示:

You can create a custom TableCellEditor for your table. This class will have an instance variable of a TextField, lets call it textField. Then the getTableCellEditorComponent method could look like this:

public Component getTableCellEditorComponent(JTable table, Object value, 
                             boolean isSelected, int row, int column ) {
    textField.setText(value.toString());
    textField.selectAll();
    return textField;
}

这篇关于开始编辑JTable Cell时选择所有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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