Question

Summary: make invisible app visible again by clicking desktop icon.

I have created a java desktop application and used Launch4j to create the executable. My application needs to run as a single instance. I have achieved this my checking that option in the Launch4j configuration GUI. When the user clicks the x button on my window (I'm using a JFrame) the window is made invisible. It is NOT disposed. When the user double clicks the system tray icon, the application window is made visible again. When the user double clicks the application desktop icon, and the application is already running, I need my main window to become visible again just like the behavior with the system tray icon.

Launch4j provides an option for a window title under the Single instance tab. I think that this option may be intended for what I need. However, when I set a window title and carry out the steps described above, I get a blank white window. With the blank white window displayed, double clicking my system tray icon will cause my app to appear in the white window. This behavior suggests that maybe changing my code relating to the top level container (Window,Frame,JFrame) might have an effect.

Do you have any ideas on how to incorporate this behavior while still using Launch4j? (it's convenient).

edit:

The core of my question is how do I define what happens when the user double clicks my executable desktop icon? If I could check for an existing instance and redirect the double click to the associated system tray icon, that would be fantastic.

Was it helpful?

Solution

I was able to accomplish my goal. In the Single Instance tab I gave the title of my main JFrame in the field for "Window title". I then added a WindowFocusListener to my main JFrame. When my JFrame receives focus, I check to see if it is already visible. If it is not, I call the appropriate method for displaying my JFrame.

The key observation is that double clicking the exe icon generated by Launch4j fires a window focus event when a window title is given in the setup. I am not sure if that is the only event that is fired, but by listening for that event, I can take whatever actions are necessary from within my java code when the user double clicks the desktop icon.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top