setOnDragDropped
John McDonnell
mcdonnell.john at gmail.com
Fri Oct 19 11:51:51 PDT 2012
Any change someone can point out the errors of my ways, when trying to drop
a node on another one?
I have simplified my code so I can show you a sample of my problem[1]. The
sample shows 2 labels. One that can be dragged, and another that is just
there to allow the dragged label to be dropped on.
In my sample when I drag the draggable node it works as expected, I even
can detected that the dragged label is dragged over the other label
listening on the onDragOver property of the second label.
But when ever I try to attach a listener to either label to detect when the
label has been dropped I am not getting any thing printed in the console.
Should the DragDropped event listener be added to the draggable label?
should the DragDropped event be fired when the mouse button is release of
the dragged label right?
[1] Sample code:
public class DropTests extends Application
{
@Override
public void start(Stage primaryStage)
{
final HBox root = new HBox();
root.setSpacing(25.0d);
Label lblDraggable = new Label();
lblDraggable.setText("'Drag me'");
lblDraggable.setOnDragDetected(new EventHandler<MouseEvent>()
{
@Override
public void handle(MouseEvent event)
{
System.out.println("Drag Detected");
Dragboard db = root.startDragAndDrop(TransferMode.ANY);
/* Put a string on a dragboard */
ClipboardContent content = new ClipboardContent();
content.putString("Label Being Dragged.");
db.setContent(content);
event.consume();
}
});
Label lblDragOver = new Label();
lblDragOver.setText("Drag over Me");
lblDragOver.setOnDragOver(new EventHandler<DragEvent>() {
@Override
public void handle(DragEvent t)
{
System.out.println("Drag Over.");
t.consume();
}
});
lblDragOver.setOnDragDropped(new EventHandler<DragEvent>() {
@Override
public void handle(DragEvent t)
{
System.out.println("Drag DROPPED");
t.consume();
}
});
root.getChildren().add(lblDragOver);
root.getChildren().add(lblDraggable);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Dragging Tests");
primaryStage.setScene(scene);
primaryStage.show();
}
--
John
More information about the openjfx-dev
mailing list