[英]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.