views:

67

answers:

2

I have an application in java swing which runs in the system tray most of the time. The user can use the Tray Menu to perform several actions. One of those actions is to show the app window. The problem I have is with usability on OS X.

In windows, if the user brings up the app window and later switches to another app, they can switch back to my application using the taskbar. But in OS X, the app runs in a mode in which the app does not have a menu and also will not appear in the Command + Tab list.

__LSUIElement is set to true in the info.plist file

So my problem is that if the user opens the app window, later switches to another app, they cannot switch back unless they click on the window itself (which could be behind many other windows). The simplest way is for the user to open the window again using the tray icon, but since the window is already open I am unable to bring it to the front.

So, How to I take focus away from other applications and bring my window to the front?

EDIT:

My issue is not with getting the 'Application running as agent'. I already have that working. The issue I have is to get my program window to the top when its created. I am unable to do this in java.

+1  A: 

You can call activateIgnoringOtherApps: with a true parameter when the user clicks on the icon in the menu bar (or however you open the window). You'll have to hook into Cocoa from Java, though.

mipadi
A: 

The code provided in the answer to the question below did the trick

http://stackoverflow.com/questions/309023/howto-bring-a-java-window-to-the-front

Virat Kadaru