Skip to content

Commit

Permalink
8294427: Check boxes and radio buttons have rendering issues on Windo…
Browse files Browse the repository at this point in the history
…ws in High DPI env

Reviewed-by: lucy
Backport-of: a63afa4aa62863d1a199a0fb7d2f56ff8fcd04fd
  • Loading branch information
Andrew Lu authored and GoeLin committed Nov 20, 2023
1 parent 046b213 commit 45e3cbf
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 97 deletions.
7 changes: 4 additions & 3 deletions src/java.desktop/share/classes/sun/swing/CachedPainter.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -314,8 +314,9 @@ public int getHeight(ImageObserver observer) {

@Override
public Image getResolutionVariant(double destWidth, double destHeight) {
int w = (int) Math.ceil(destWidth);
int h = (int) Math.ceil(destHeight);
int w = (int) Math.floor(destWidth + 0.5);
int h = (int) Math.floor(destHeight + 0.5);

return getImage(PainterMultiResolutionCachedImage.class,
c, baseWidth, baseHeight, w, h, args);
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -40,10 +40,13 @@

package com.sun.java.swing.plaf.windows;

import java.awt.*;
import java.util.*;

import javax.swing.*;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.Point;
import java.util.EnumMap;
import javax.swing.JComponent;

import sun.awt.windows.ThemeReader;

Expand All @@ -55,7 +58,7 @@
*
* @author Leif Samuelsson
*/
class TMSchema {
public final class TMSchema {

/**
* An enumeration of the various Windows controls (also known as
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -40,23 +40,52 @@

package com.sun.java.swing.plaf.windows;

import java.awt.*;
import java.awt.image.*;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.awt.image.WritableRaster;
import java.security.AccessController;
import java.util.*;

import javax.swing.*;
import javax.swing.border.*;
import javax.swing.plaf.*;
import java.util.HashMap;

import javax.swing.AbstractButton;
import javax.swing.CellRendererPane;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JRadioButton;
import javax.swing.JToolBar;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.border.AbstractBorder;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import javax.swing.plaf.ColorUIResource;
import javax.swing.plaf.InsetsUIResource;
import javax.swing.plaf.UIResource;
import javax.swing.text.JTextComponent;

import sun.awt.image.SunWritableRaster;
import sun.awt.windows.ThemeReader;
import sun.security.action.GetPropertyAction;
import sun.swing.CachedPainter;

import static com.sun.java.swing.plaf.windows.TMSchema.*;

import static com.sun.java.swing.plaf.windows.TMSchema.Part;
import static com.sun.java.swing.plaf.windows.TMSchema.Prop;
import static com.sun.java.swing.plaf.windows.TMSchema.State;
import static com.sun.java.swing.plaf.windows.TMSchema.TypeEnum;

/**
* Implements Windows XP Styles for the Windows Look and Feel.
Expand Down Expand Up @@ -675,14 +704,20 @@ protected void paintToImage(Component c, Image image, Graphics g,
w = bi.getWidth();
h = bi.getHeight();

// Get DPI to pass further to ThemeReader.paintBackground()
Graphics2D g2d = (Graphics2D) g;
AffineTransform at = g2d.getTransform();
int dpi = (int)(at.getScaleX() * 96);

WritableRaster raster = bi.getRaster();
DataBufferInt dbi = (DataBufferInt)raster.getDataBuffer();
// Note that stealData() requires a markDirty() afterwards
// since we modify the data in it.
ThemeReader.paintBackground(SunWritableRaster.stealData(dbi, 0),
part.getControlName(c), part.getValue(),
State.getValue(part, state),
0, 0, w, h, w);
0, 0, w, h, w, dpi);

SunWritableRaster.markDirty(dbi);
}

Expand Down

1 comment on commit 45e3cbf

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.