diff --git a/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkTitlePane.java b/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkTitlePane.java index ad3e8866..fa3a1dd7 100644 --- a/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkTitlePane.java +++ b/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkTitlePane.java @@ -57,8 +57,7 @@ public class DarkTitlePane extends JComponent { private static final int BAR_HEIGHT = (int) (56 / GraphicsUtil.SCALE_Y); private static final int BUTTON_WIDTH = (int) (92.5 / GraphicsUtil.SCALE_X); private static final int ICON_WIDTH = (int) (65 / GraphicsUtil.SCALE_X); - private static final int IMAGE_HEIGHT = 16; - private static final int IMAGE_WIDTH = 16; + private static final int ICON_SIZE = ICON_WIDTH - 3 * PAD; private final JRootPane rootPane; private final ContainerListener rootPaneContainerListener = new ContainerListener() { @Override @@ -581,12 +580,17 @@ public class DarkTitlePane extends JComponent { List icons = window.getIconImages(); assert icons != null; - Icon systemIcon; if (icons.size() == 0) { systemIcon = UIManager.getIcon("TitlePane.icon"); + } else if (icons.size() == 1) { + systemIcon = new ScaledIcon(icons.get(0).getScaledInstance((int) (ICON_SIZE * GraphicsUtil.SCALE_X), + (int) (ICON_SIZE * GraphicsUtil.SCALE_Y), + Image.SCALE_AREA_AVERAGING)); } else { - systemIcon = new ImageIcon(SunToolkit.getScaledIconImage(icons, IMAGE_WIDTH, IMAGE_HEIGHT)); + systemIcon = new ScaledIcon(SunToolkit.getScaledIconImage(icons, (int) (ICON_SIZE * GraphicsUtil.SCALE_X), + (int) (ICON_SIZE * GraphicsUtil.SCALE_Y)) + ); } if (windowIconButton != null) { windowIconButton.setIcon(systemIcon); @@ -762,4 +766,32 @@ public class DarkTitlePane extends JComponent { setActive(false); } } + + protected static class ScaledIcon implements Icon { + + private Image img; + + @Contract(pure = true) + protected ScaledIcon(final Image img) { + this.img = img; + } + + @Override + public void paintIcon(final Component c, final Graphics g2, final int x, final int y) { + var g = (Graphics2D) g2; + g.translate(x, y); + g.scale(1.0 / GraphicsUtil.SCALE_X, 1.0 / GraphicsUtil.SCALE_Y); + g.drawImage(img, 0, 0, img.getWidth(null), img.getHeight(null), null); + } + + @Override + public int getIconWidth() { + return (int) (img.getWidth(null) / GraphicsUtil.SCALE_X); + } + + @Override + public int getIconHeight() { + return (int) (img.getHeight(null) / GraphicsUtil.SCALE_Y); + } + } } diff --git a/src/main/resources/com/github/weisj/darklaf/platform/windows/x64/jniplatform.dll b/src/main/resources/com/github/weisj/darklaf/platform/windows/x64/jniplatform.dll index ee793773..ab3d928f 100644 Binary files a/src/main/resources/com/github/weisj/darklaf/platform/windows/x64/jniplatform.dll and b/src/main/resources/com/github/weisj/darklaf/platform/windows/x64/jniplatform.dll differ diff --git a/src/main/resources/com/github/weisj/darklaf/platform/windows/x86/jniplatform.dll b/src/main/resources/com/github/weisj/darklaf/platform/windows/x86/jniplatform.dll index df9ddebf..275bd612 100644 Binary files a/src/main/resources/com/github/weisj/darklaf/platform/windows/x86/jniplatform.dll and b/src/main/resources/com/github/weisj/darklaf/platform/windows/x86/jniplatform.dll differ diff --git a/src/test/java/UIDemo.java b/src/test/java/UIDemo.java index 518dbfaf..6233415d 100644 --- a/src/test/java/UIDemo.java +++ b/src/test/java/UIDemo.java @@ -38,6 +38,10 @@ public final class UIDemo { taskpanecontainer.add(taskpane); JFrame frame = new JFrame("UIDemo"); + frame.setIconImage(Toolkit.getDefaultToolkit().createImage( + UIDemo.class.getClassLoader().getResource("mima.png") + )); + Icon folderIcon = IconLoader.get().getUIAwareIcon("files/folder.svg", 19, 19); var panel = new JPanel(new GridLayout(3, 4)); diff --git a/src/test/resources/mima.png b/src/test/resources/mima.png new file mode 100644 index 00000000..6a91daa8 Binary files /dev/null and b/src/test/resources/mima.png differ