How can I display multiple dock items for jFrames within one Java application?

138 views Asked by At

I have a modular Java application: a single jar launches a 'control panel', from which the user can open several modules. Each module uses its own jFrame. (A discussion of whether this is a good or bad practice can be found here - in my case the modules all talk to one another but perform different functions).

Running on Windows, each module (jFrame) gets its own icon on the taskbar, and is selectable via ALT-tab. On OS X I only get one dock icon and one icon in the Application Switcher (CMD-tab). This makes it quite awkward to switch between modules, several of which will be open at any one time.

How can I put each module (jFrame) in the OS X dock and Application Switcher separately?

Iterestingly, if I iconise one of the jFrames, it does appear in the dock, in the right-hand area by the Trash.

I am testing this using Java 7 on OS X 10.10 (Yosemite). I have made a cheat's .app which launches the jar via a shell script, in order to provide cmd-line arguments (Xdock:name etc) and icons - so I do have an info.plist file.

1

There are 1 answers

1
martinez314 On BEST ANSWER

You can't. The OS X user interface just doesn't work that way.

Iterestingly, if I iconise one of the jFrames, it does appear in the dock, in the right-hand area by the Trash.

This is user-configurable. See Preferences > Dock > Minimize windows into application dock.

Rather than fight against the normal OS behavior, come up with your own "module switcher" feature, perhaps making it part of your control panel. You will find that application switching and dock icon behavior differs a lot across operating systems. Trying to make OS X behave like Windows, or vice-versa, outside the bounds of your application will be a big headache.

That said, if you don't want to heed the above advice, the only way I can think of to do what you want is to create dummy applications, that don't display any windows, but that do show up in the dock. The dummy applications can be started by your main application. When a dummy application is clicked, it can then signal your main application (perhaps listening on a local open port) to make one of the modules active. This would give the illusion that each module had its own place in the dock. This would probably work with the Alt-Tab switcher as well.