Skip to content

Commit

Permalink
MainGui: set icon for Taskbar
Browse files Browse the repository at this point in the history
Use java.awt.Taskbar added in Java 9 to set the taskbar icon image. This
mainly affects macOS, as far as I know, which doesn't automatically take
the icon of the JFrame (`window`).

The default Duke icon will be replaced by the Resoday logo in the macOS
dock.  The downside is that macOS doesn't segregate different Java
applications, so all apps running under with the same binary file `java`
are gathered under the one icon.
  • Loading branch information
rybak committed Aug 11, 2023
1 parent bcce805 commit b82824e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
- Rendering of the icon in the title bar of the main window has been
fixed in Microsoft Windows.
- Dock on macOS will now show the Resoday icon instead of the default
Duke icon of the JVM.

v1.5
- Fixed dead link in "About" dialog
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/dev/andrybak/resoday/gui/Logo.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public static List<Image> getImages() {
);
}

public static Image getMultiResolutionImage() {
Image icon32 = getImage(APP_ICON_32_FILENAME);
Image icon64 = getFixedResolutionImage();
return new BaseMultiResolutionImage(icon32, icon64);
}

private static Image getImage(String filename) {
URL url = Objects.requireNonNull(MainGui.class.getResource(filename));
return Toolkit.getDefaultToolkit().getImage(url);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/dev/andrybak/resoday/gui/MainGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.awt.BorderLayout;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.Taskbar;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
Expand Down Expand Up @@ -388,6 +389,9 @@ private void goInEdt(Path configDir) {
* Can't use Logo.getMultiResolutionImage() here because of a JDK bug on Linux.
*/
window.setIconImages(Logo.getImages());
if (Taskbar.isTaskbarSupported() && Taskbar.getTaskbar().isSupported(Taskbar.Feature.ICON_IMAGE)) {
Taskbar.getTaskbar().setIconImage(Logo.getMultiResolutionImage());
}
window.setVisible(true);
window.addWindowListener(new WindowAdapter() {
@Override
Expand Down

0 comments on commit b82824e

Please sign in to comment.