java - catch event of double click on icon in tray

后端 未结 6 1133

I want to make my form visible when I double click the tray icon?
How do I catch the double click on the icon?
Thanks.

6条回答
  •  鱼传尺愫
    2020-12-07 02:06

    trayIcon.addMouseListener(new java.awt.event.MouseAdapter() {
    
        @Override
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            if (evt.getClickCount() == 2) {
                setVisible(true);
                setExtendedState(JFrame.NORMAL);
            }
        }
    
    });
    tray.add(trayIcon);
    

    This will do the job.

提交回复
热议问题