On Tue, 22 Feb 2022 22:54:24 GMT, Emmanuel Bourg <[email protected]> wrote:
>> When a list of icons is set on a window, the most appropiate icon is
>> selected depending on the graphics configuration. But if the graphics
>> configuration changes (because the window is moved to a different screen, or
>> because the DPI settings of the screen is changed), the frame icon isn't
>> updated.
>>
>> Here is an example illustrating the issue:
>>
>> public static void main(String[] args) throws Exception {
>> SwingUtilities.invokeLater(() -> {
>> JFrame frame = new JFrame("Window Icon Test");
>> frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
>> frame.setSize(400, 300);
>> frame.setVisible(true);
>>
>> List<Image> images = new ArrayList<>();
>> for (int size = 16; size <= 32; size++) {
>> // create an image displaying the size used
>> BufferedImage image = new BufferedImage(size, size,
>> BufferedImage.TYPE_INT_ARGB);
>> Graphics2D g = image.createGraphics();
>> g.setFont(new Font("dialog", Font.BOLD, 12));
>> g.setColor(Color.BLACK);
>> g.drawString(String.valueOf(size), 0, size - (size -
>> g.getFont().getSize()) / 2);
>> images.add(image);
>> }
>>
>> frame.setIconImages(images);
>> });
>> }
>>
>> On Windows if the screen scaling is set to 100% the 16x16 icon is picked
>> from the list. If the scaling of the screen is set to 150% while the
>> application is running, the 16x16 icon is upscaled and looks blurry.
>>
>> A way to work around this issue is to listen for graphics configuration
>> changes with:
>>
>> frame.addPropertyChangeListener("graphicsConfiguration", event ->
>> frame.setIconImages(frame.getIconImages()));
>>
>>
>> Ideally this should be done automatically by the JDK. Maybe the `WindowPeer`
>> could call `updateIconImages()` when `updateGraphicsData()` or
>> `displayChanged()` is invoked?
>
> Emmanuel Bourg has updated the pull request incrementally with two additional
> commits since the last revision:
>
> - Test case for the window icon update on DPI change (Java generic font
> names are usually capitalized)
> - Test case for the window icon update on DPI change (dispose the frame
> after a timeout on the EDT)
I tested on macOS 12 with a Retina display and the build with and without your
fix, the icon for minimised frame always displays 32. The icon stays the same
on the external monitor too even if I disable Retina mode for it.
> The issue observed on Windows doesn't really transpose to macOS, I think I'll
> revert the change to `LWWindowPeer`.
Sounds reasonable because the issue doesn't affect macOS, as it seems.
-------------
PR: https://git.openjdk.java.net/jdk/pull/6180