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.
Is this possible?
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Since
TrayIconsupports bothaddMouseListener()andaddMouseMotionListener()you should implement your listeners to care about the state of the selection/focus of theTrayBar..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
mouseEnteredormouseExited, and so on.TrayIcondoesn’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
TrayIconobject but I don’t know how well this is implemented, just try it out by yourself.