ADDITIONAL SYSTEM INFORMATION :
Windows 10, JDK EA 15 Build 6
A DESCRIPTION OF THE PROBLEM :
It's correct that you can pass a MultiResolutionImage to createCustomCursor. However, only the base image is looked at, as is quite obvious from the respective JDK code:
https://github.com/openjdk/jdk/blob/6bab0f539fba8fb441697846347597b4a0ade428/src/java.desktop/share/classes/sun/awt/CustomCursor.java
and
https://github.com/openjdk/jdk/blob/dd570ee6c85ed6f6093755efc17ce21258c538f9/src/java.desktop/windows/classes/sun/awt/windows/WCustomCursor.java
Providing a large image (e.g. 64x64 according to getBestCursorSize) indeed gives you a HiDPI cursor. However, having attached both a HiDPI (200% scaling) screen and a regular screen (100% scaling) at the same time, this makes the cursor appear at double size on the regular screen.
If you consider this a different problem than JDK-8139152, please open a new bug.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached test program and hover the mouse over the opened window.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A HiDPI cursor on the HiDPI screen, a normal DPI cursor on the regular screen, both having about the same size.
ACTUAL -
A HiDPI cursor on the HiDPI resolution, a normal DPI cursor on the normal DPI screen, the latter having twice the size.
(Too bad no screenshots can be attached here.)
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BaseMultiResolutionImage;
import java.awt.image.BufferedImage;
public class CustomCursorResolution {
public static void main(String[] args)
{
Dimension bestCursorSize = Toolkit.getDefaultToolkit().getBestCursorSize(32, 32);
assert bestCursorSize.width == bestCursorSize.height; // effectively 64 for systems with (also) a HiDPI screen
final int cursorSize = bestCursorSize.width;
// construct framed haircross
BufferedImage bufferedImageLowRes = createCursorImage(cursorSize / 2);
BufferedImage bufferedImageHighRes = createCursorImage(cursorSize);
Frame frame = new Frame();
BaseMultiResolutionImage mrImage = new BaseMultiResolutionImage(bufferedImageHighRes, bufferedImageLowRes);
frame.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(
mrImage, new Point(cursorSize / 2, cursorSize / 2), "haircross"));
frame.setSize(new Dimension(500, 500));
frame.setVisible(true);
}
private static BufferedImage createCursorImage(int cursorSize) {
BufferedImage bufferedImage = new BufferedImage(cursorSize, cursorSize, BufferedImage.TYPE_INT_ARGB);
Graphics2D bg = bufferedImage.createGraphics();
bg.setBackground(new Color(1.0f, 1.0f, 1.0f, 0.0f));
bg.clearRect(0, 0, cursorSize, cursorSize);
bg.setColor(Color.BLACK);
bg.drawRect(0, 0, cursorSize - 1, cursorSize - 1);
bg.setStroke(new BasicStroke(2));
bg.drawLine(cursorSize / 2, 0, cursorSize / 2, cursorSize);
bg.drawLine(0, cursorSize / 2, cursorSize, cursorSize / 2);
return bufferedImage;
}
}
---------- END SOURCE ----------
FREQUENCY : always