How to change WM_CLASS value in Java GUI application on Swing or NetBeans platform?

All Swing / NetBeans-based Java GUI applications have the same meaning WM_CLASS:

WM_CLASS(STRING) = "sun-awt-X11-XFramePeer", "java-lang-Thread"

This parameter can be viewed by issuing a command xpropand pointing to a window. The practical purpose of setting it up is to allow Mac-like docks (e.g. AWN (and possibly Ubuntu Unity)) to distinguish application windows and group them under the application icon. For this to work, the StartupWMClassparameter must be set accordingly in the file .applicationin ~/.local/share/applicationsor /usr/share/applications. Of course, AWN (and peers) are confused if more than one application uses the same string for WM_CLASS.

+5
source share
1

Toolkit, , awtAppClassName. , :

Toolkit xToolkit = Toolkit.getDefaultToolkit();
java.lang.reflect.Field awtAppClassNameField = xToolkit.getClass().getDeclaredField("awtAppClassName");
awtAppClassNameField.setAccessible(true);
awtAppClassNameField.set(xToolkit, applicationName);
+2

All Articles