Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JTable,Can';当光标仍指向单元格内部时,无法检索特定单元格上的数据_Java_Swing_Jtable_Tablecelleditor - Fatal编程技术网

Java JTable,Can';当光标仍指向单元格内部时,无法检索特定单元格上的数据

Java JTable,Can';当光标仍指向单元格内部时,无法检索特定单元格上的数据,java,swing,jtable,tablecelleditor,Java,Swing,Jtable,Tablecelleditor,我想发布一张照片,但我在这个网站上没有声誉,但我在下面描述了我的问题: | Name | Grade | __________________ | Febri | 60| <---- if this is a cell (row0,column1), I can't retrieve data on this cell if cursor is still pointing inside th

我想发布一张照片,但我在这个网站上没有声誉,但我在下面描述了我的问题:

| Name | Grade | __________________ | Febri | 60| <---- if this is a cell (row0,column1), I can't retrieve data on this cell if cursor is still pointing inside that cell. take a look : System.out.println(mytable.getValueAt(0,0)); --> output : Febri System.out.println(mytable.getValueAt(0,1)); -- > output : that's because my mouse's cursor is still pointing inside that cell .. Any suggestions? Is this problem related to mouse listener? Please help , thx. 你的例子(大部分)很好

我想你的意思是,当单元格可编辑时,它不会返回编辑器显示的值

这是有意义的,因为编辑器包含的值尚未提交到模型

您可以做的是停止当前的编辑过程,如果表在编辑模型中,这将从编辑器向模型提交值,然后您可以读取该值

public void actionPerformed(ActionEvent e) {
    if (e.getSource() == button) {
        // Is the table in edit mode?
        if (table.isEditing()) {
            // Get the current editor
            TableCellEditor editor = table.getCellEditor();
            if (editor != null) {
                // Try and stop the cell editing process
                if (!editor.stopCellEditing()) {
                    // Cancel the editing if can't be stopped...
                    // You could handle an error state here instead...
                    editor.cancelCellEditing();
                }
            }
        }
        System.out.println(table.getValueAt(0, 0));
        System.out.println(table.getValueAt(0, 1));
    }
}
当然,这一切都取决于你想要实现的目标……

你的例子(大部分)运行良好

我想你的意思是,当单元格可编辑时,它不会返回编辑器显示的值

这是有意义的,因为编辑器包含的值尚未提交到模型

您可以做的是停止当前的编辑过程,如果表在编辑模型中,这将从编辑器向模型提交值,然后您可以读取该值

public void actionPerformed(ActionEvent e) {
    if (e.getSource() == button) {
        // Is the table in edit mode?
        if (table.isEditing()) {
            // Get the current editor
            TableCellEditor editor = table.getCellEditor();
            if (editor != null) {
                // Try and stop the cell editing process
                if (!editor.stopCellEditing()) {
                    // Cancel the editing if can't be stopped...
                    // You could handle an error state here instead...
                    editor.cancelCellEditing();
                }
            }
        }
        System.out.println(table.getValueAt(0, 0));
        System.out.println(table.getValueAt(0, 1));
    }
}


当然,这一切都取决于您试图实现的目标……

您需要停止编辑单元格。显示了两种方法。一个由MadProgrammer演示,另一个允许您在JTable上设置属性。

您需要停止编辑单元格。显示了两种方法。一个由MadProgrammer演示,另一个允许您在JTable上设置属性。

如果可能,发布示例代码您的意思是该单元格仍然可编辑?如果可能,发布示例代码您的意思是该单元格仍然可编辑?+1属性,请注意,在Java 6下,当表位于
JInternalFrame
中时,这将不起作用。欢迎来到我的生命中的2年…因此,示例代码的原因是:PApparently它与
JInternalFrame
的自动对焦错误有关,该错误应该在5-6月修复。它似乎是固定在7虽然…仍然不能回到我的生活抓我的头两年。最后复制整个
JTable
代码来包装我们自己的解决方案…在这两种情况下都不高兴:PThx回复,我将使用类似“停止”编辑的方式在谷歌上搜索教程n我稍后报告结果..它已经用MadProgrammer的方式工作了,感谢您抽出时间回答我的问题+1对于属性,请注意,在Java 6下,当表位于
JInternalFrame
中时,这将不起作用…欢迎来到我的生命中的2年…因此示例代码的原因是:paparently它与
JInternalFrame
的自动聚焦错误有关,该错误应该在5-6之间修复。它似乎是固定在7虽然…仍然不能回到我的生活抓我的头两年。最后复制整个
JTable
代码来包装我们自己的解决方案…在这两种情况下都不高兴:PThx回复,我将使用类似“停止”编辑的方式在谷歌上搜索教程n我稍后报告结果..它已经用MadProgrammer的方式工作了,感谢您抽出时间回答我的问题!!!Thx,对于replay,是的,这是因为当我们仍然编辑该单元格上的值时,表不会提交该单元格上的数据。但我仍在等待真正的实施(至少是一个例子),等待你的建议,任何你可以推荐我去的网站或讨论??你所说的“真正的实施”是什么意思?这两个答案中的任何一个,只要我们实现了您想要的——在它提交到模型之前,您无法从单元格中获得值——这就是现实……我的意思是“教程/示例”,您的答案是正确的,但我不知道如何在Java代码中实现它?当然,我不能简单地写“myTable.setEnable(false)”;“你可以看看哇,我没有看到你已经用“TableCellEditor”为我创建了解决方案,我以为你只是重复了我的代码,对不起:D,谢谢你,我会试试……Thx,对于回放,是的,这是因为当我们还在编辑那个单元格上的值时,该表不会提交该单元格上的数据。但我仍在等待真正的实施(至少是一个例子),等待你的建议,任何你可以推荐我去的网站或讨论??你所说的“真正的实施”是什么意思?这两个答案中的任何一个,只要我们实现了您想要的——在它提交到模型之前,您无法从单元格中获得值——这就是现实……我的意思是“教程/示例”,您的答案是正确的,但我不知道如何在Java代码中实现它?当然,我不能简单地像“myTable.setEnable(false);”这样写,“你可以看看哇,我没有看到你已经用“TableCellEditor”为我创建了解决方案,我以为你只是重复了我的代码,对不起:D,谢谢你,我会试试的。。。。