[英]Hover over system Tray and open a balloon in Java
How do I hover over the system Tray and open a balloon in Java ? 如何将鼠标悬停在系统托盘上并用Java打开气球? I 'am able to open a tool tip , but not able to open a balloon .
我可以打开工具提示,但不能打开气球。
However, I can right click on the icon and do a actionPerformed and do this to open a balloon 但是,我可以右键单击该图标并执行一个操作,然后执行此操作以打开一个气球
trayIcon.displayMessage(title, message, TrayIcon.MessageType.INFO)
You can always emulate tooltip behavior yourself with a MouseListener and MouseMotionListener: 您始终可以使用MouseListener和MouseMotionListener自己模拟工具提示行为:
String message = "Application running";
int hoverTime = 1000;
Timer messageTimer = new Timer(hoverTime,
e -> trayIcon.displayMessage(null, message,
TrayIcon.MessageType.INFO));
messageTimer.setRepeats(false);
trayIcon.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent event) {
messageTimer.restart();
}
@Override
public void mouseExited(MouseEvent event) {
messageTimer.stop();
}
});
trayIcon.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseMoved(MouseEvent event) {
messageTimer.restart();
}
});
Note that Timer
is a javax.swing.Timer, not a java.util.Timer, as the former guarantees its action will be executed in the AWT event dispatch thread. 请注意,
Timer
是一个javax.swing.Timer,而不是java.util.Timer,因为前者保证其动作将在AWT事件分派线程中执行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.