Skip to main content

Drag and drop

1 reply [Last post]
Joined: 2008-01-24

Hi to everybody, this is my first post here, hope this is the right place an sorry for my bad english.

I need to drag and drop between two Nodes in a canvas, I looked at the api of JavaFX and i found out that it seems all set up but I can't get it to work. Actually the drop works is the drag that doesn't, here is part of my code:

Circle {
opacity: 0.7
cx: bind xpos+215+me.radius
cy: bind ypos+25+me.radius
radius: 15
fill: cornflowerblue
exportDrag: true
onMouseDragged: operation(e:CanvasMouseEvent){
System.out.println("drag x:{e.x }y: {e.y}");
exportAsDrag: function():CanvasDragEvent{

return CanvasDragEvent{
source: me
dragValue: myJavaObject
dragView: Circle{
radius: 5
fill: red
canAcceptDrop: operation(e:CanvasDropEvent){
System.out.println("can accept dorp");
return true;
onDragExit: operation(e:CanvasDropEvent){
System.out.println("drag exit");

onDrop: operation(e:CanvasDropEvent){
System.out.println("on dorp");

if the attribute exportDrag is set to true the Node doesn't receive anymore the onMouseDragged event, and since the exportAsDrag is a function I have no idea how I can know if it is invoked. Also onDragExit seems not to work...

Thanks in advance for any answer.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2007-05-18

Drag and drop is being addressed aggressively in compiled JavaFX Script. So far, UI widgets are being worked on, and as I understand it, the "Node" side of JavaFX Script will be dealt with next (and hopefully soon).

FWIW, I highly recommend that developers jump in and play with compiled JavaFX Script. The compiler team could really use the help in identifying issues that occur when real-life scenarios are being developed. When you find them, enter them into JIRA with a very simple program that reproduces the problem that you find. For example, I suggest that you try the program that you submitted in this post in compiled JavaFX Script and submit a JIRA issue if the drag doesn't work.

See the following posts in my "Helping You Become a JavaFXpert" weblog to get started in compiled JavaFX script:

Obtaining the OpenJFX Script Compiler:

Compiled JavaFX Script Rosetta Stone - In Progress:

Jim Weaver