我有一个带有一些项目的JList.我已经为选择列表中的项目时添加了一个监听器.以下是选择列表中的项目时发生的代码:
private void questionaireNamesListValueChanged(ListSelectionEvent evt) {
try {
inputPanel.setEnabled(false);
inputPanel.setVisible(false);
inputTextField.setText("");
inputStatusLabel.setText("");
int questionaireIndex = questionaireNamesList.getSelectedIndex();
// Why will this be printed twice?
System.out.println("Questionaire Index: " + questionaireIndex);
if (remoteQuestionServer.getQuestionCount(questionaireIndex) == 5) {
answerQuestionButton.setEnabled(true);
addQuestionButton.setEnabled(false);
} else {
addQuestionButton.setEnabled(true);
answerQuestionButton.setEnabled(false);
}
} catch (RemoteException ex) {
ex.printStackTrace();
}
}
如上所示,我将System.out.print语句放入其中,每次单击列表中的某些内容时,我都会获得该项目的两个输出,例如.
Questionaire Index: 4
Questionaire Index: 4
Questionaire Index: 2
Questionaire Index: 2
Questionaire Index: 0
Questionaire Index: 0
Questionaire Index: 2
Questionaire Index: 2
知道为什么会这样吗?
谢谢,
帕特里克