[英]Selecting row and column of the Jtable by clicking the jCombobox that is inside a column of jtable
在我的Jtable实例中,一列具有jComboBox,现在我想要的是一旦选定的jcombobox的值更改后,就选择单元格的行和列。
如果我使用jcombobox的actionPerformed事件,并获取jtable.getSelectedrow和column。 系统给我最后选择的行和列,而不是当前的行和列。
请指导我该怎么办..谢谢
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);
}
现在,我想要的是一旦选定的jcombobox的值更改后,就选择单元格的行和列。
不要将ActionListener添加到组合框中,这不是设计表编辑器的方式。
相反,您应该向JTable
的TableModel
中添加TableModelListener
。 只要表中的数据发生更改,就会生成一个事件。 该事件将包含已更改的单元格的行/列。
有关工作示例,请查看: TableModelListener和多列验证
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.