The Source for Java Technology Collaboration

Home » java.net Forums » OpenJFX » JavaFX Script Language Discussion

Thread: Drag 'n Drop

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
This question is not answered. Helpful answers available: 2. Correct answers available: 1.

Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 5 - Last Post: Aug 8, 2008 6:41 AM by: stanhirsh Threads: [ Previous | Next ]
stanhirsh

Posts: 8
Drag 'n Drop
Posted: Aug 1, 2008 2:48 AM
 
  Click to reply to this thread Reply

Hi all,

is there some D&D functionality in the SDK ? Is it possible to make an object draggable and to enable another object (e.g. a simple rectange) to to recieve drops and broadcast onDrop events ?

Thanks, Stan

alexsch

Posts: 238
Re: Drag 'n Drop
Posted: Aug 1, 2008 2:58 AM   in response to: stanhirsh
 
  Click to reply to this thread Reply

Below is a simple example:

import javafx.input.*;
import javafx.application.*;
 
import javafx.scene.paint.*;
import javafx.scene.geometry.*;
 
import java.lang.System;
 
var x = 100.0;
var y = 30.0;
 
Frame {
    title: "Circle"
    width:  200
    height: 100
    stage: Stage{
        content: Circle {
            centerX: bind x
            centerY: bind y
            radius: 25
            fill: Color.ORANGE
            stroke: Color.GREEN
 
            onMouseDragged: function(e:MouseEvent) {
                    x = e.getX();
                    y = e.getY();
                }
 
        }
    }
    visible: true   
}


alexsch

Posts: 238
Re: Drag 'n Drop
Posted: Aug 1, 2008 2:59 AM   in response to: stanhirsh
 
  Click to reply to this thread Reply

See JFXC-1263 Add Drag and Drop to javafx.gui http://openjfx.java.sun.com/jira/browse/JFXC-1263

stanhirsh

Posts: 8
Re: Drag 'n Drop
Posted: Aug 1, 2008 8:28 AM   in response to: alexsch
 
  Click to reply to this thread Reply

Hi,

thanks for the quick reply. So moving objects around works pretty fine :-), but how can I make another object realize, that something has been dropped on it ?

Thanks, Stan

sleep

Posts: 18
Re: Drag 'n Drop
Posted: Aug 2, 2008 6:26 AM   in response to: stanhirsh
 
  Click to reply to this thread Reply

When you are dragging something and release the mouse, the dragged object gets the endDrag-Event, not the item you are currently over. However, you can work out your own dropping code because while you are dragging, mouseOver-events are still caused whenever you move over a node. So simply have objects watch whether something is being dragged over them and have the endDrag-event cause the drag processing.

stanhirsh

Posts: 8
Re: Drag 'n Drop
Posted: Aug 8, 2008 4:25 AM   in response to: sleep
 
  Click to reply to this thread Reply

Hi and thanks for the idea with the workaround, but is there really no built in DnD support, that would also allow me to pull a node out of a canvas and let´s say drop it on a tree-view-list in another window ?

Thanks, Stan

Edit: Apparently there was meant to be some native support for DnD - not sure if it is still there. Check:
http://markmail.org/message/42sdqq7zwtthelbg#query:javafx%20%22drag%20and%20drop%22%20-browser%20order%3Adate-backward+page:4+mid:42sdqq7zwtthelbg+state:results

Message was edited by: stanhirsh




 XML java.net RSS