JDK-8028212 : Custom cursor HiDPI support
  • Type: Enhancement
  • Component: client-libs
  • Affected Version: 8
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2013-11-12
  • Updated: 2017-05-24
  • Resolved: 2014-01-09
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9 Other
8u20Fixed 9 b06Fixed openjdk7uFixed
Related Reports
Relates :  
Description
This is a request for HiDPI support for custom cursors.
See http://mail.openjdk.java.net/pipermail/macosx-port-dev/2013-November/006211.html

http://docs.oracle.com/javase/6/docs/api/java/awt/Toolkit.html#createCustom
Cursor(java.awt.Image, java.awt.Point, java.lang.String)
Comments
I have 2 files which contain a cursor image with different sizes. If NSImage is created with representations from these files and set NSCursor, the first image is always shown on both non-Retian and Retina display (I use the Quartz Debug). If representations size is divided by the screen scale factor --------- NSSize size = [imgRep size]; [imgRep setSize:NSMakeSize(size.width /scaleFactor, size.height / scaleFactor)]; -------- the high-resolution image is correctly shown for the NSCursor on Retina display. See the samples. NSImage representations are not scaled. The bigger image is not shown for the cursor on Retina: ------------------------------------ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { [self performSelector:@selector(doChangeCursor) withObject:nil afterDelay:1]; } - (void) showRepresentations: (NSImage *) image { NSImageRep *img = nil; NSArray *images = [image representations]; NSEnumerator *imageEnumerator = [images objectEnumerator]; while ((img = [imageEnumerator nextObject]) != nil) { NSSize size = [img size]; NSLog(@"Image variant size[%f, %f]", size.width, size.height); } } - (void) doChangeCursor { NSString *file = @"/tmp/cursor/image.png"; NSString *file2x = @"/tmp/cursor/image2.png"; NSImage *image = [[NSImage alloc] initWithContentsOfFile:file]; NSImage *image2x = [[NSImage alloc] initWithContentsOfFile:file2x]; [image addRepresentations: [image2x representations]]; [self showRepresentations:image]; //[self rescaleRepresentations:image]; NSCursor *cursor = [[NSCursor alloc] initWithImage:image hotSpot:NSMakePoint(0, 0)]; [cursor set]; } ------------------------------------ NSImage representations are scaled. The bigger image is correctly shown for the cursor on Retina: ------------------------------------ - (void) rescaleRepresentations: (NSImage *) image { NSImageRep *img = nil; NSArray *images = [image representations]; NSEnumerator *imageEnumerator = [images objectEnumerator]; int scaleFactor = 1; while ((img = [imageEnumerator nextObject]) != nil) { NSSize size = [img size]; NSLog(@"Image variant size[%f, %f]", size.width, size.height); [img setSize:NSMakeSize(size.width /scaleFactor, size.height / scaleFactor)]; size = [img size]; NSLog(@"Image updated size[%f, %f]", size.width, size.height); scaleFactor++; } } - (void) doChangeCursor { NSString *file = @"/tmp/cursor/image.png"; NSString *file2x = @"/tmp/cursor/image2.png"; NSImage *image = [[NSImage alloc] initWithContentsOfFile:file]; NSImage *image2x = [[NSImage alloc] initWithContentsOfFile:file2x]; [image addRepresentations: [image2x representations]]; //[self showRepresentations:image]; [self rescaleRepresentations:image]; NSCursor *cursor = [[NSCursor alloc] initWithImage:image hotSpot:NSMakePoint(0, 0)]; [cursor set]; }
29-11-2013