0
通過單擊表單的其他空間來清除JTable選擇的最佳方式是什麼? 我嘗試這樣做:Java:通過單擊表格的其他空間清除JTable中的選擇
table1.addFocusListener(new MyTableFocusListener());
...
public class MyTableFocusListener implements FocusListener {
@Override
public void focusLost(FocusEvent e)
{
table1.getSelectionModel().clearSelection();
}
@Override
public void focusGained(FocusEvent e)
{
}
}
但有例外:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
你有沒有使用剛剛試過['JTable中#clearSelection'(http://docs.oracle.com/javase/7/docs/api/javax/swing/JTable.html#clearSelection()) – MadProgrammer