Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to alter WM_CLASS value in a Java GUI application based on Swing or NetBeans Platform?

All Swing/NetBeans-based Java GUI applications seem to have the same WM_CLASS value:

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

This parameter can be viewed by issuing xprop command and pointing to the window. The practical purpose of customizing it is to let Mac-like docks (AWN, for example (and, perhaps, Ubuntu's Unity)) distinguish the application windows and group them under the application's pinned launcher icon. For this to work StartupWMClass parameter is to be set accordingly in the .application file in ~/.local/share/applications or /usr/share/applications. Needless to say, AWN (and analogues) get confused in case more than one application uses the same string for WM_CLASS.

like image 876
Ivan Avatar asked May 15 '12 01:05

Ivan


1 Answers

This blog post found the field in Toolkit that controls it, named awtAppClassName. It suggests using reflection to modify it:

Toolkit xToolkit = Toolkit.getDefaultToolkit();
java.lang.reflect.Field awtAppClassNameField = xToolkit.getClass().getDeclaredField("awtAppClassName");
awtAppClassNameField.setAccessible(true);
awtAppClassNameField.set(xToolkit, applicationName);
like image 189
sethjust Avatar answered Sep 18 '22 18:09

sethjust