Swing: steal focus from other applications (usability in OS X)

I have an application in java swingthat runs in the system tray most of the time. The user can use Tray Menuto perform several actions. One of these actions is to show the application window. I have a usability issue on OS X.

In windows , if a user opens an application window and then switches to another application, he can return to my application using the taskbar . But in OS X, the application works in a mode in which the application does not have a menu, and will also not be displayed in the list Command + Tab.

__LSUIElement set to true in info.plist file

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

So, how do I divert attention from other applications and bring my window to the foreground?

EDIT:

My problem is not that "the application works as an agent . " I already have a job. The problem is that my program window is on top when it was created. I can not do this in java.

+3
3

, ,

?

+1

activateIgnoringOtherApps: true, (, , ). Cocoa Java.

+1

, , :

try {
    String[] cmd = new String[2];
    cmd[0] = "open";
    cmd[1] = "/Applications/MyApp.app";

    Runtime.getRuntime().exec(cmd);
}
catch(Exception ex) {
    //ignore since there nothing else that can be done
}

, JVM, "open" Mac OS X, , java-, . , , , .

+1

Source: https://habr.com/ru/post/1757015/