我需要在 SwingX JXDatePicker 组件上激活 MouseListener,使我能够在用户单击组件时执行特定操作。不幸的是,该事件从未被触发。
特此重现问题的一小段代码:
public class TestDummy4 extends JFrame implements MouseListener{
private static final long serialVersionUID = -2424758762078571430L;
public TestDummy4(){
super();
this.getContentPane().setLayout(new BorderLayout());
//Adds date picker
JXDatePicker dp = new JXDatePicker();
dp.getEditor().setEditable(false);
dp.getEditor().setHighlighter(null);
dp.addMouseListener(this);
this.getContentPane().add(dp);
this.pack();
this.setVisible(true);
}
public static void main(String[] args) throws IOException {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
//Builds GUI
new TestDummy4();
}
});
}
@Override
public void mouseClicked(MouseEvent e) {
System.out.println("Mouse clicked");
}
@Override
public void mousePressed(MouseEvent e) {
System.out.println("Mouse pressed");
}
@Override
public void mouseReleased(MouseEvent e) {}
@Override
public void mouseEntered(MouseEvent e) {
System.out.println("Mouse Entered");
}
@Override
public void mouseExited(MouseEvent e) {}
}
使用此代码,单击 JXDatePicker 时,控制台上没有一行输出。
任何帮助/提示将不胜感激!托马斯