0

Here is the code. I want to ask why is that mouseClicked for a trayicon works perfectly but mouseEntered won't work at all?

mouseListener = new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent e) {
      
        if (e.getButton() == MouseEvent.BUTTON1) {
            showStage(stage);
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                }
            });
        }
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        // why this cant be triggerd
        trayIcon.displayMessage(
            "警告", "这是一个警告提示!", TrayIcon.MessageType.WARNING);
    }
};
trayIcon.addMouseListener(mouseListener);
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433

1 Answers1

0

After

trayIcon.addMouseListener(mouseListener);

add this line:

trayIcon.addMouseMotionListener(mouseListener);