You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently looking into this, as part of trying to get general app icons for Linux. For that, there are, as far as I can tell, two approaches:
have a globally-installed the-app.desktop file describing the program and its icon location (and the app setting a WM_CLASS hint to associate to it); seems impossible to make work via just setIcon, but would be good to have as a WindowX11-only thing for those wanting to do proper X11 application association;
set via pixels; this could be bound to setIcon, but means something has to decode the png (or whatever file format).
I have both WM_CLASS configuring and icon-from-pixels configuring for X11 here via a temporary interface, using Skija to decode the png in the dashboard example. (the class isn't used by the example, but e.g. an OS-global icon theme could now set a custom icon for it)
I understand that setting icon is more of a packaging problem and probably can’t be easily solved by just doing API calls, but where it can work I don’t see why not have it
The above method won't work if the icon is a resource in an application's jar file; in that case, the icon is just a stream of bytes embedded in the jar file. I suggest JWM should add a new method for such use case:
publicabstractWindowsetIcon(byte[] icon);
Browsing the dashboard example application, the paths to the physical icons are hard-coded in the application's code:
I don't know about Mac or X11, but I think the X11 case is already solved in this thread/commits.
For Windows, Java doesn't have a built-in way to parse the .ico file, so we need to use native Windows APIs. Assuming the byte[] array are raw bytes from a .ico file, we can use the following Win32 functions exported by user32.dll:
LookupIconIdFromDirectoryEx: Inspects raw icon bits and returns the exact integer resource identifier (offset) for the icon version that best fits your display resolution.
CreateIconFromResourceEx: Builds the HICON handle from the raw resource bits once the correct offset is identified.
I've done some prototype code with the above 2 functions and they work fine, although I use Java FFM to prototype, not JNI C header.
But I'm not sure what JWM can do with the given Windows HICON handle. How can JWM use the handle to "set the icon" to the window?
Activity
dzaima commentedon Sep 24, 2024
Currently looking into this, as part of trying to get general app icons for Linux. For that, there are, as far as I can tell, two approaches:
the-app.desktopfile describing the program and its icon location (and the app setting aWM_CLASShint to associate to it); seems impossible to make work via justsetIcon, but would be good to have as aWindowX11-only thing for those wanting to do proper X11 application association;setIcon, but means something has to decode the png (or whatever file format).I have both
WM_CLASSconfiguring and icon-from-pixels configuring for X11 here via a temporary interface, using Skija to decode the png in the dashboard example. (the class isn't used by the example, but e.g. an OS-global icon theme could now set a custom icon for it)tonsky commentedon Sep 27, 2024
Both look good, make a PR?
I understand that setting icon is more of a packaging problem and probably can’t be easily solved by just doing API calls, but where it can work I don’t see why not have it
chirontt commentedon Jun 19, 2026
The above code is working for X11, but what about other platforms such as Mac and Windows?
Currently the Window class contains only one method: to load the icon from a physical file in the file system:
JWM/shared/java/Window.java
Line 205 in b921797
The above method won't work if the icon is a resource in an application's
jarfile; in that case, the icon is just a stream of bytes embedded in the jar file. I suggest JWM should add a new method for such use case:Browsing the
dashboardexample application, the paths to the physical icons are hard-coded in the application's code:JWM/examples/dashboard/java/Example.java
Lines 82 to 87 in b921797
which allows only one place to run the application in order to properly load the physical icon file. This is too limited/restrictive.
Instead, the code can be enhanced to use the above new
setIcon(byte[])method:where
loadIconResourceis a utility method that returns the icon resource as a stream of bytes:tonsky commentedon Jun 20, 2026
If OS API allows for that (e.g. it doesn’t require you to point at file on disk) then I am all in for byte[]
chirontt commentedon Jun 22, 2026
I don't know about Mac or X11, but I think the X11 case is already solved in this thread/commits.
For Windows, Java doesn't have a built-in way to parse the
.icofile, so we need to use native Windows APIs. Assuming the byte[] array are raw bytes from a.icofile, we can use the following Win32 functions exported byuser32.dll:LookupIconIdFromDirectoryEx: Inspects raw icon bits and returns the exact integer resource identifier (offset) for the icon version that best fits your display resolution.
CreateIconFromResourceEx: Builds the HICON handle from the raw resource bits once the correct offset is identified.
I've done some prototype code with the above 2 functions and they work fine, although I use Java FFM to prototype, not JNI C header.
But I'm not sure what JWM can do with the given Windows HICON handle. How can JWM use the handle to "set the icon" to the window?
tonsky commentedon Jun 22, 2026
I don’t know :) But I also think changing icon of a running application is a very narrow use-case
chirontt commentedon Jun 26, 2026
PR #310
With this PR, I can now create a
dashboardnative image using GraalVM.Merge branch 'windows_icon_in_bytes' #310 #135