我有两个JList,jltCategories和jltSubcategories,属于同一个JPanel。双击jltCategories会导致jltSubcategories填充相应的子类别,jltSubcategories将从JPanel中删除,添加回来并重新验证。
双击jltSubcategories后,它被删除/添加后不会触发任何内容。然而,如果我打开程序并双击jltSubcategories,它将触发其鼠标事件:如果尚未删除/添加它将触发,但如果已删除/添加它将不会触发。对于jltCategories也是如此:如果我将其删除/添加,它将停止触发。为什么会这样?谢谢!
jltCategories.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() > 1) {
jbtNavigate.doClick();
}
}
});
jltSubcategories.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() > 1) {
jbtLoad.doClick();
}
}
});
jbtNavigate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String catName = jltCategories.getSelectedValue();
try {
jpLists.remove(jltSubcategories);
jltSubcategories = new JList<String>(SQL.populateSubcategories(catName));
jpLists.add(jltSubcategories);
jpLists.revalidate();
} catch (SQLException e1) {
e1.printStackTrace();
}
}
});
jbtLoad.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Testing Testing 213");
}
});