JDK-8076106 : [macosx] Drag image of TransferHandler does not honor MultiResolutionImage
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 9
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x
  • CPU: x86
  • Submitted: 2015-03-26
  • Updated: 2015-09-29
  • Resolved: 2015-04-14
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
8u60Fixed 9 b65Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
OpenJDK 64-Bit Server VM (build 1.9.0-internal-hendrik_2015_03_26_15_38-b00, mixed mode)

However, the same thing is true of 8u40.

ADDITIONAL OS VERSION INFORMATION :
Darwin Mankell 14.1.0 Darwin Kernel Version 14.1.0: Thu Feb 26 19:26:47 PST 2015; root:xnu-2782.10.73~1/RELEASE_X86_64 x86_64

A DESCRIPTION OF THE PROBLEM :
javax.swing.TransferHandler supports a custom image that appears when dragging via setDragImage(Image).

When provided a MultiResolutionImage on OSX the higher resolution is unfortunately ignored.

The reason for this is that in sun.lwawt.macosx.CImage the necessary adjustment for MultiResolutionImage was apparently forgotten for the method createFromImageImmediately(), which is called from the drag mechanism.

A JDK9 patch can be found at https://www.beatunes.com/download/webrev-multiresolutiondragimage.zip

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute test case below.
A window appears with a text field.
Drag the content of the text field.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
On a Retina display, the drag image should be RED.
On a regular display, the drag image should be BLUE.
ACTUAL -
The drag image is always BLUE.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------

import sun.awt.image.MultiResolutionToolkitImage;

import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;

public class MultiResolutionsDragImage {


    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            final JFrame frame = new JFrame();
            frame.setBounds(100, 100, 300, 300);
            final JTextField label = new JTextField("Drag Me");
            label.setDragEnabled(true);
            final TransferHandler transferHandler = label.getTransferHandler();
            transferHandler.setDragImage(createMultiResolutionImage());
            frame.getContentPane().add(label);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
        });
    }

    private static Image createMultiResolutionImage() {
        return new MultiResolutionToolkitImage(createImage(50, Color.BLUE), createImage(100, Color.RED));
    }

    private static Image createImage(final int length, final Color color) {
        final BufferedImage image = new BufferedImage(length, length, BufferedImage.TYPE_INT_ARGB_PRE);
        final Graphics graphics = image.getGraphics();
        graphics.setColor(color);
        graphics.fillRect(0, 0, length, length);
        graphics.dispose();
        return image;
    }
}
---------- END SOURCE ----------