我有一个包含一些项目的 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
知道为什么会这样吗?
谢谢,帕特里克