Check if system tray focused in Java?
I have a Java app that has an icon in the system tray.
How can I check if the tray (or tray icon) has current focus?
Tray and TrayIcon don't seem to have .isFocused() or similar.开发者_如何学C
Is this possible?
Thanks!
Since TrayIcon
supports both addMouseListener()
and addMouseMotionListener()
you should implement your listeners to care about the state of the selection/focus of the TrayBar
..
you could try to see which events are fired when you focus it or unfocus. It depends on what you want to catch: if you want to see whenever the user hovers onto the icon you should try with mouseEntered
or mouseExited
, and so on. TrayIcon
doesn't inherit from any standard GUI component so I think this is the only way to work with it.
In addition I won't rely too much of making it work cross-platform since probably these kinds of events are fired from the OS and sent to JVM that forwards them to the TrayIcon
object but I don't know how well this is implemented, just try it out by yourself.
精彩评论