Cyr*_*rad 15 java swing jtable event-handling
对所选行的任何更改JTable都会触发添加ListSelectionListener两次是否正常?
是否有可能ListSelectionListener只触发一次?
MeB*_*Guy 26
请特别注意传递给侦听器的事件
ListSelectionEvent.getValueIsAdjusting()
Run Code Online (Sandbox Code Playgroud)
当返回false时,执行你想要做的任何操作.
小智 5
ListSelectionEvent.getValueIsAdjusting() 将按照@MeBigFatGuy 的评论工作。
类似的例子:
if(!e.getValueIsAdjusting()){
String selectedData = null;
int selectedRow = table.getSelectedRow();
int selectedColumns = table.getSelectedColumn();
for (int i = 0; i <= selectedRow; i++) {
for (int j = 0; j <= selectedColumns; j++) {
selectedData = (String) table.getValueAt(selectedRow, selectedColumns);
}
}
System.out.println("Selected: " + selectedData);
}
Run Code Online (Sandbox Code Playgroud)
它只会被触发一次。