每当JTable中存在lostFocus时,我需要捕获现有单元格的行和列。如何在FocusLost事件期间获取JTable selectedRow和selectedColumn
但是,以下条件始终为false,因为源始终是JTextField或JComboBox。
public void focusLost(FocusEvent e) {
int row, col;
Object source = e.getSource();
if(((Component) source).getParent() instanceof JTable_Ext){ //<-- always false
table = (JTable_Ext) ((Component) source).getParent();
row = table.getSelectedRow();
col = table.getSelectedColumn();
}
为了缓解上述问题,我记得FocusGained(作为类级变量)时的行和列。问题是,如果用户在JTable中的所有位置点击非常快,那么行和列信息将不同步。
有没有办法在FocusLost期间获得行和列?如果没有,是否有更好的方法来做到这一点?
对面的组件是一个javax.swing.JViewport。不是JTable – Reusable 2011-06-09 13:16:00