为什么第一次点击时没有选择我的JTable行?每次首次点击后都会选中它。有什么问题?
我需要从单击的行中获取所有值。这是我的代码。从第二次点击开始效果很好。
private void tblAccountInfoMouseReleased(java.awt.event.MouseEvent evt) {
try {
DefaultTableModel model = (DefaultTableModel) tblAccountInfo.getModel();
txtUserName.setText(model.getValueAt(tblAccountInfo.getSelectedRow(), 0).toString());
try {
txtPassword.setText(model.getValueAt(tblAccountInfo.getSelectedRow(), 1).toString());
} catch (NullPointerException npe) {
}
try {
txtType.setText(model.getValueAt(tblAccountInfo.getSelectedRow(), 2).toString());
} catch (NullPointerException npe) {
}
try {
txtUrl.setText(model.getValueAt(tblAccountInfo.getSelectedRow(), 3).toString());
} catch (NullPointerException npe) {
}
updateId = tblAccountInfo.getSelectedRow();
btnSave.setEnabled(false);
btnUpdate.setEnabled(true);
btnDelete.setEnabled(true);
} catch (ArrayIndexOutOfBoundsException aiobe) {
aiobe.printStackTrace();
}
}