How to make a JWS application pinnable to the Windows 7 taskbar? - java

I'm deploying applications using Java Web Start.
To my surprise, one can pin programs to the taskbar in Windows 7, however to my understanding this is only possible if the process in which the program runs is the same than the one that is behind the taskbar icon.
With a JWS application, that's not the case so the application can not be pinned to the taskbar, as shown in the following example:
The "u" is my application shortcut, pinned (from the start menu). The other (ugly) icon is the actual application, ran in another process, creating another icon which cannot be pinned. I only get the "Close window" option.
Would it be possible to have a pinnable JWS application?

Related

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

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.
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.

Changing the icon shown in a taskbar group for a multi window application

On Windows 7 an application can control how to group their Windows on the taskbar. Windows has some default settings related to the executable, how the shortcut was created, the name of the program, etc. to apply some default grouping. The problem with host based applications like Java, is that the same executable is used by many programs so Windows has some registry settings to set that javaw.exe is a host app. When this happens, applications must configure at runtime how to group Windows and enable pin to taskbar. I am already setting Application User Model IDs in order to group Windows as needed.
The problem that I haven't found solution is that for a multi window application: how to set a stable icon to be used on the taskbar?. The default Windows behavior for an application, say for example with two windows, where each windows has his own icon, the task bar icon shows the icon of the first opened window, if that window is closed it changes to the other one, and the process is repeated every time windows are opened and closed.
There is some API to set the icon when the user pin an application to the taskbar setting System.AppUserModel.RelaunchIconResource window property, but the documentation says that this icon is used when the app is being pinned, so according to that it only is used if the application is running from that pinned applications, leaving the problem open for applications that are not able to be pinned (or that the developer do not want to allow pinning).
There are options like generating a new executable with the icon (launching the JVM from that application), creating a shortcut with the correct AppUserModelID. Those aren't solutions for me because the application is distributed using Java WebStart/JNLP, so the application shortcut is created by Java and the launcher is a marked as a host application (as it should)
the other solution is to set the same icon to each window when running on Windows 7, that icon, with the exception of the taskbar one, is not very prominent on Windows 7 on Aero mode, but with Aero disabled it is, it is the icon used on the Alt+tab switcher without windows previews, something I want to leave looking different for each windows
Note: This is a tagged Java but really is a question for any platform that use a host executable (javaw.exe, python.exe ...)

Creating single instance for system tray in java

I am working in a desktop application created in java. we are working for windows version (for running on windows O.S.) of the application. When we run our application, it creates a tray icon on desktop by using systemtray as
SystemTray tray = SystemTray.getSystemTray();
I am creating single instance of the system tray, which I am creating in the main class of the application.
I am creating exe for my application. My problem is when i am running the exe file of my application, it creates tray icon every time.
I want in my application only one tray icon present on desktop and running as a service. this icon should only get removed, when application is uninstalled. It should run as service in the background.
I am not getting any way which will help me to run my application as a service and there should be only one instance running in the background.
I want to run my application by creating a tray icon as a service and should have single instance present. Please guide me in this issue.
Thanks for your all valuable suggestions in advance.
As Mudassir said, you should add a check when you start your program that tries to find another running instance of your app. This could be done by creating a specific file upon startup, and deleting it on close. If the file is already present when you start your app, it means that another instance is running.
You could also use inter-process communications, but it would be more difficult than a simple file.
For the "service" part, you could hide the main window on startup, so your app will run as if it was a windows service.
Make your application Single Instance. And please tell how you are making an .EXE file in Java?
For a tray icon to appear, your app must be running. If your tray icon appears to be there twice (or more), than your application runs multiple times. You have to add a check for this yourself.
You don't want to run your app as a windows service, as normally these have no access to the Windows Desktop.

Opening a LWJGL window from a SWT app on Mac

I have a SWT app that opens a OpenGL window (using the LWJGL library) after a button is pressed. It is supposed to close it's main SWT window and open a new one with an OpenGL context. Works fine on Windows. On Mac, I get this error:
2010-03-05 02:28:25.315 java[1315:a07] [Java CocoaComponent compatibility mode]: Enabled
2010-03-05 02:28:25.316 java[1315:a07] [Java CocoaComponent compatibility mode]: Setting timeout for SWT to 0.100000
2010-03-05 02:28:25.317 java[1315:a07] Apple AWT Startup Exception : _createMenuRef called with existing principal MenuRef already associated with menu
2010-03-05 02:28:25.318 java[1315:a07] Apple AWT Restarting Native Event Thread
The SWT window closes and then the app hangs, with no windows open.
It looks like the SWT app doesn't shut down cleanly and leaves it's menu entries associated with it, which prevents the LWJGL window from opening. Mac OS X only wants one application menu. SWT doesn't free it's own menu and LWJGL wants to add another.
Facts:
A button in the SWT dialog is supposed to close the dialog and open a LWJGL window (org.lwjgl.opengl.Display).
The button sets a static variable in the app to tell it what to do next after the SWT window is closed, so the LWJGL window is NOT being opened from a SWT callback directly.
The button then closes the SWT window. I don't know the correct way of doing this but tried various combinations of shell.close, shell.dispose, display.close and display.dispose, none of them worked. They all close the window but the error occurs every time.
Does anyone know what could be done to make this work?
UPDATE: This simply does not work and it seems that Apple will not fix it, ever. The only way around it is to launch a new app instance and pass it a parameter that tells it to open the second window.
UPDATE 2: In this particular case, I solved the problem by using the SWT dialog for the Windows version of the app and for the Mac version, I wrote a native Cocoa dialog which invokes the JVM and runs the LWJGL app when needed. That works pretty well.
It would appear to me that the problem is not SWT creating a new window or LWJGL actually doing so. I believe the problem lies in the fact that under Mac, the application menu must be registered to the process, and for some reason or another, there is a conflict of interest between the two.
You might have some better luck juggling things around a little:
What happens when you create a LWJGL window first, then create a SWT shell?
What happens when you initialize LWJGL statically before creating a SWT shell, then proceed to create the shell and create an LWJGL window?
Incidentally, to close a SWT window, all you need to do is dispose of the Shell:
shell.dispose();

JNLP doesn't show splash screen when launching from a desktop icon

I have been able to create a JNLP file, which successfully sets up a splash screen & a desktop icon for a Java program launched through Web Start. Here's the relevant chunk of the JNLP:
Now, to launch the program, I find I can either click on the JNLP, in which case the splash screen shows, or on the desktop icon, in which case the default Java Web Start splash screen shows instead. This is on Windows XP & Windows Vista, and it's Java 1.5 and Java 1.6.
Is there a way to get my splash screen to show when launching from the JNLP file, instead of the Java one?
Thanks.
Updating to the most recent minor upgrade of Java 6 seems to have fixed this, at least on the Windows platforms. So I am now on update 16. I was on 9 before I think, and this has been fixed somewhere along the line.
First thing I should have tried? Probably!

Categories