JDK-8089069 : Dragboard setDragView doesn't work with JFXPanel
Type:Bug
Component:javafx
Sub-Component:swing
Affected Version:emb-8u26
Priority:P4
Status:Open
Resolution:Unresolved
Submitted:2014-02-12
Updated:2018-09-05
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.
The Dragboard setDragView(image) API doesn't work with a JFXPanel in a Swing app.
Comments
If effects like this weren't critical to JavaFX, we would all stick with Swing. :-)
Lack of this feature makes JavaFX feel like a 90's toolkit. I'll bet it's hard to find any modern app that only shows a cursor on drag.
14-04-2014
Does dragging images not work? I thought this bug was specifically about the setDragView() method. This method isn't used to DnD images, but rather only to add a visual representation of data being dragged. It is a useful feature, I'm not arguing with that. But it isn't critical.
14-04-2014
Why is this bug scheduled for version 9? Drag-n-drop of images is basic functionality for rich applications these days.
14-04-2014
I just realized there is a (seemingly) harmless exception that gets thrown at the end, on DragDrop, that goes away if I comment out the setDragView() call:
java.lang.ClassCastException: java.nio.HeapByteBuffer cannot be cast to java.io.InputStream
at sun.awt.datatransfer.DataTransferer.translateTransferable(DataTransferer.java:1372)
at sun.lwawt.macosx.CDataTransferer.translateTransferable(CDataTransferer.java:131)
at sun.awt.datatransfer.DataTransferer$6.run(DataTransferer.java:2380)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:744)
< more event queue stuff ��� >
12-02-2014
Here is some sample code:
public class DragFXSwing {
static JFXPanel _jfxp;
public static void main(String args[])
{
JFrame frame = new JFrame();
frame.setContentPane(_jfxp = new JFXPanel()); _jfxp.setPreferredSize(new Dimension(400,400));
Platform.runLater(new Runnable() { public void run() { initJFX(); }});
frame.show();
}
static void initJFX()
{
final Label label = new Label("Hello World");
label.setOnDragDetected(new EventHandler() {
public void handle(Event anEvent) {
Dragboard db = label.startDragAndDrop(TransferMode.ANY);
try { db.setDragView(new Image(new FileInputStream(new File("/Users/jeff/Desktop/Logo.gif")))); }
catch(Exception e) { }
ClipboardContent cc = new ClipboardContent(); cc.putString("Hello World"); db.setContent(cc);
anEvent.consume();
}
});
_jfxp.setScene(new Scene(label, 400, 400));
}
}
12-02-2014
This functionality should work in theory. However, it is unimplemented yet. We will take a look at it in a future release.
Please attach a simple test case to this issue if possible.