对JTable
的选定行进行的任何更改是否会触发添加的ListSelectionListener
两次,这是否正常?为什么JTable总是触发ListSelectionListener两次?
是否有可能ListSelectionListener
只能触发一次?
对JTable
的选定行进行的任何更改是否会触发添加的ListSelectionListener
两次,这是否正常?为什么JTable总是触发ListSelectionListener两次?
是否有可能ListSelectionListener
只能触发一次?
看看传递给您的侦听器的事件,特别是
ListSelectionEvent.getValueIsAdjusting()
执行要做到这时候返回false什么欢声笑语。
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);
}
它会只是一次触发。
谢谢@ jrbedard – joshdlv 2016-12-04 19:39:55
谢谢...这解决了这个问题... – 2011-05-03 05:27:24
你可以给一些更详细的答@MeBigFatGuy – 2016-08-27 04:21:31