当尝试通过双击从列表中选择项目时,它为两个列表选择一次,但在单击选择后!!!
listScrollPanel.setViewportView(categoryList);
subCategoryList.setModel(new javax.swing.AbstractListModel() {
String[] strings = {"Sub-category 1", "Sub-category 2", "Sub-category 3", "Sub-category 4", "Sub-category 5", "Sub-category 6"};
});
subCategoryList.addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseClicked(java.awt.event.MouseEvent evt) {
infoBox(Integer.toString(evt.getClickCount()), subCategory);
if (evt.getClickCount() == 2) {
subCategoryList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
@Override
public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
subCategoryListValueChanged(evt);
}
});
}
}
});
private void subCategoryListValueChanged(javax.swing.event.ListSelectionEvent evt) {
subCategory = (String) subCategoryList.getSelectedValue();
labelSC.setText(CAT_HEADER);
listScrollPanel.setViewportView(categoryList);
}
private static void infoBox(String Message, String location) {
JOptionPane.showMessageDialog(null, Message, location, JOptionPane.INFORMATION_MESSAGE);
}
怎么让他只听双击?我有 categoryList ,双击后 ListSelection 将 viewportView 更改为 subCategory ,它的工作原理相同!但他们在前两次双击后单击反应!