【问题标题】:Selecting row and column of the Jtable by clicking the jCombobox that is inside a column of jtable通过单击 jtable 列内的 jCombobox 选择 Jtable 的行和列
【发布时间】:2016-12-06 00:26:54
【问题描述】:

在我的 Jtable 实例中,一列具有 jComboBox ,现在我想要的是在更改所选 jcombobox 的值后选择单元格的行和列。

如果我使用 jcombobox 的 actionPerformed 事件,并获取 jtable.getSelectedrow 和列。系统给我最后选择的行和列,而不是当前的行和列。

请指导我该怎么做..谢谢

private void jComboBoxActionPerformed(java.awt.event.ActionEvent evt) {                                                                  


            DefaultTableModel model = (DefaultTableModel) jTable.getModel();

            int selectedRow = jTable.getSelectedRow();
            int selectedColumn = jTable.getSelectedColumn();

            System.out.println("Row : " + selectedRow);
            System.out.println("Column : " + selectedColumn);
        } 

【问题讨论】:

标签: java swing


【解决方案1】:

现在我想要的是在所选 jcombobox 的值发生更改后选择单元格的行和列。

不要将 ActionListener 添加到组合框,这不是表格编辑器的设计使用方式。

相反,您应该将TableModelListener 添加到JTableTableModel。每当表中的数据发生更改时,都会生成一个事件。该事件将包含已更改单元格的行/列。

查看工作示例:TableModelListener and multiple column validation

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-02
    • 1970-01-01
    • 2017-10-08
    • 1970-01-01
    • 2017-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多