JTree Drag & Drop question.  DragSourceDragEvent vs DropTargetDragEvent

I'm implementing Drag and Drop within a JTree.
I need to get the TreeNode as the user drags over it. This method works for a DropTargetDragEvent:
private TreeNode getNodeForEvent(DropTargetDragEvent dtde)
              Point p = dtde.getLocation();
              DropTargetContext dsc = dtde.getDropTargetContext();
              JTree tree = (JTree)dsc.getComponent();
              TreePath path = tree.getClosestPathForLocation(p.x, p.y);
              System.out.println("DropTargetDragEvent: Closet path for tree locaiton is " + path);
              return (TreeNode)path.getLastPathComponent();
        } But this method for DragSourceDragEvent returns a node much farther down on the JTree than where the user is dragging.
private TreeNode getNodeForEvent(DragSourceDragEvent dsde)
         Point p = dsde.getLocation();
         DragSourceContext dsc = dsde.getDragSourceContext();
         JTree tree = (JTree)dsc.getComponent();
         TreePath path = tree.getClosestPathForLocation(p.x, p.y);
         System.out.println("DragSourceDragEvent: Closet path for tree locaiton is " + path);
         return (TreeNode)path.getLastPathComponent();
   } Am I missing something? The first method I found on this site. The 2nd method I modified since I need the node based on a DragSourceDragEvent because that's where I can set a custom cursor based on the node type.
Has anyone run into this before?
Thanks

I've figured out why this is happening but am not sure how to fix it.
For DropTargetDragEvent getLocation() returns the cursors position within the component.
For DragSouceDragEvent getLocation returns the cursors position on the screen.
Sortof makes sense but I don't know how to get a position over a component from the position on the screen.

Similar Messages

  • Quiz Template Guru Needed: 1) Target Symbols from Drag&Drop questions persist on subsequent questions!??

    I've been finding some anomalies when testing the movie, for
    instance the question regarding the BA degree keeps telling me the
    answer marked correct in the Component Inspector (# 6 American
    Urban) is incorrect; other times it seems one question contains
    part of another question's graphics, though I have scrupulously
    made sure there is no overlap frame by frame.
    I need someone with experience in quiz templates to go
    through this until you find anomalies like those mentioned above,
    and let me know if you have any idea what's causing them.
    You can download the .fla at
    http://mywebniche.com/test/FrontDeskTest.zip
    The test can be seen at
    http://mywebniche.com/test/FrontDeskTest1.html
    [Note: The Name Field's actionscript is also not working.
    When you enter your name on the first frame, it should appear on
    the results page -- doesn't. Any idea what's wrong there?]
    This is a real project and I really need help getting it bug
    free.
    Thanks.

    I have the solution. It is a bug in Flash for which I got
    them to find a workaround.
    If you ask me they don't spend nearly enought time/energy on
    Flash in education, particularly the quizzes, which have so many
    limitations and are lacking so many obviously needed features.
    I'll post their workaround below, but I want you, and all who
    read it to contact their feedback/wishlist for Flash and complain
    about their Quizzes getting short shrift. Features badly needed
    are:
    - Ability to randomize AND require certain questions to
    always appear.
    - options to enter name and have it appear on Results Page
    along with date and number of times the quiz has been re-taken.
    - the ability to have multiple true/false questions
    - better documentation on how to customize the template
    graphics and how to use original graphics
    - fix the drag & drop component permanently -- this is
    arguably the most useful question format of them all !
    - ability to save customized components -- as component
    templates
    - anything else you can think of that I haven't included here
    Here's the fix:
    1) in your movie, locate an instance of the Drag and Drop
    Interaction component and select it.
    2) Select Edit Symbols from the file menu (Edit > Edit
    Symbols) to edit the symbol
    3) The middle layer should be the Actions Layer.  Select
    frame 1 in that Actions layer and open the Actions panel
    4) Scroll to the bottom of the script and find the
    this.onUnload function located there.
    5) Use your mouse and highlight the contents of that
    function, not including the function name, and copy it.  You
    should have copied the following script:
     var clearLast =
    _parent.SessionArray[_parent.session].drag_objects;
     var len = clearLast.length;
     for(var i=0; i<len; i++){
      _parent[clearLast
    ].removeMovieClip();
    6) Return to the very top of the script and paste a copy of
    this script there prior to the comment stating:
    /*--------------VERSION CONTROL
    INFORMATION----------------------
    Note: You may need to make some room for the new script.
    What this should do is ensure that the unload script is
    called immediately upon the loading of a new drag and drop
    interaction component clearing any prior objects used in the one
    before it.  This was not happening appropriately before
    which is what was causing those dragged objects to remain on the
    screen.

  • Drag/Drop Question

    I have implemented drag & drop using a datagrid and a list control. The items that need to be dragged are a simple value object that conatin data. Everything works as far as the drag/drop operations, however, I need to be able to know which item has been dropped. It's probably simple, but I can't find it. Can anyone help?

    Just give each item an id
    and listen to the
    <s:List id="destList"
         dragDrop="destList_dragDropHandler(event)"

  • AS3 to AS3 Drag/Drop Question

    This is a fairly routine drag/drop interaction. The tricky part is when the invisilbe button 'btnInvis10' is clicked, another movieClip, 'dragger' appears and becomes the element being dragged, to be dropped onto 'mSquare'.  AS3 is giving me some problems when I convert the code - really just changing the functions to be AS3 compliant. But I guess it needs more than just converting. Any ideas?
    My AS2 code worked like this:
    dragger._alpha = 0;
    btnInvis10.onPress = function():Void  {
    dragger._alpha = 100;
    dragger.startDrag(true);
    onMouseUp = function ():Void {
    var bOverlap:Boolean = dragger.hitTest(mSquare);
    //trace(bOverlap);
    if (bOverlap) {
      dragger._alpha = 0;
      btnInvis10._visible = false;
      menubar._x = _xmouse;
      menubar._y = _ymouse;
      gotoAndStop(nextFrame());
      bOverlap = false;
    if (!bOverlap) {
      dragger._alpha = 0;
      dragger._x = 412;
      dragger._y = 490;
    dragger.stopDrag();

    Can you show your AS3 attempt as well?
    I figure I should ask if the coding is errant wrt the way you test if bOverlap is true vs false (since it may be as intended).  In the first conditional where it is true, it is set to false, which will cause the condition that follows it to also run since it is now false...
    if (bOverlap) {
      bOverlap = false;
    if (!bOverlap) {
    One last thing... gotoAndStop(nextFrame());  doesn't make sense (to me).  nextFrame does not return a value, so using it as an argument doesn't buy anything.  By itself it will cause the timeline to move to the next frame and stop.

  • Multiple Selection in JTree, Drag & Drop

    Hi everybody,
    I was wondering if anyone knows how to implement Multiple Selection Drag and Drop in a JTree. I know that there used to be a bug in jdk 1.3 that would allow it, but I suspect 1.4 fixed that. I've implemented Single-selection just fine, but I'm trying do Multiple selection by drawing a selection rectangle and selecting whatever nodes are contained within that rectangle. So far I've implemented it by adding a MouseListener to my JTree, finding which rows are intersected by the rectangle and calling addSelectionRow() to add the TreePaths.
    Is there an easier way to multiple selection now that the bug of 1.3(I hope) has been fixed?

    Okay, now I've implemented the changes in the DragGestureListener, DragSourceListener and DragTargetListener in order to make Multiple Selection possible, however I want to select multiple items the same way Windows Explorer does by:
    1. pressing the left-mouse button & dragging a "selection" rectangle which selects all the nodes contained within that rectangle.
    2. then drag and drop is accomplished by pressing one of the selected nodes and dragging it (along with it's other selected siblings) to the destination.
    In order to accomplish this I added into the Constructor of my JTree extending class this code:
    public class MyTree extends JTree {
    private static int x1, y1, x2, y2;
    public MyTree(DefaultMutableTreeNode rootNode){
    // Other Constructor stuff...
    this.addMouseMotionListener( new MouseMotionListener() {
    public void mouseDragged(MouseEvent e) {  
    x2 = e.getX();
    y2 = e.getY();
    repaint();
    public void mouseMoved(MouseEvent e){     }
    this.addMouseListener(new MouseAdapter(){
    boolean dontRelease = false;
    public void mousePressed( MouseEvent e){
    x1 = e.getX();
    y1 = e.getY();
    int[] rows = getSelectionRows();
    boolean dropSel = true;
    if (rows != null){
    for (int i = 0; i < rows.length; i++){
    Rectangle rect3 = getRowBounds(i);
    if (rect3.contains(x1, y1)){
    dropSel = false;
    dontRelease = true;
    if (dropSel){
    for (int i =0; i < rows.length; i++)
    removeSelectionRow(i);
    public void mouseReleased( MouseEvent e){
    x2 = e.getX();
    y2 = e.getY();
    repaint();
    if (dontRelease == false) {
    Rectangle rect2 = new Rectangle(Math.min(x1, x2),
    Math.min(y1, y2), Math.abs(x1-x2), Math.abs(y1-y2));
    int rowCount = getRowCount();
    for (int i = 1; i < rowCount; i++) {
    Rectangle rect3 = getRowBounds(i);
    if ((rect2.contains(rect3)) || (rect2.intersects(rect3))){
    addSelectionRow(i);
    dontRelease = false;
    repaint();
    The idea was that for every press of the mouse the 1st set of x,y coords. are taken to be the starting corner of the "selection" rectangle, and every point passed over while dragging would be the ending corner of the rectangle (so that in paintComponents, you could actually draw the rectangle).
    Once the mouse is released it will check to see if the selection rectangle had contained or intersected any of the rows (basically I find how many rows are being shown in the tree and go through each one to see if there is intersection/containment). If a row is contained it becomes selected.
    The remaining code in MousePressed is used if node(s) were previously selected it goes through and checks to see if this mouse press is at the location of one of the previous selected nodes - if it is then you can drag that node along with all of its siblings to their destination. However if your mouse press is not on one of the selected nodes - all the nodes should be deselected (like in explorer if you press away from your selection, you lose it). If you select and begin to drag your selection dontRelease should not allow the creation of another "selection" rectangle to occur during the drag-n-drop process.
    -That's how I thought this code should work. Unfortunately as it does most of these things it does not correctly implement rule #2 of Windows Explorer (2. only by dragging one of the selected nodes can you drag them, otherwise you lose them)...currently as long as something is selected you can do a mouse press and drag from another location and as long as that location does not contain a node (like it is a blank area in the JTree), you can drag everything to the destination from when you start dragging.
    I looked around and saw that perhaps it is due to the BasicTreeUI interferring with it's own MouseInputHandler() so I wrote MyTreeUI that extends BasicTreeUI, basically changing only the MouseInputHandler to contain the functions above, and I blocked /**/ those functions from my MyTree Constructor.
    Then in my main class (the one of instantiate my MyTree and my DefaultMutableTreeNodes), I wrote:
    try
    String myTreeUI = "MyTreeUI";
    UIManager.put( "MyTreeUI", myTreeUI );
    UIManager.put( myTreeUI,
    Class.forName( myTreeUI ) );
    } catch( ClassNotFoundException cnfe ) {
    System.err.println( "My Tree UI class not found" );
    System.err.println( cnfe );
    ...thinking that that would be all I needed in order to set MyTreeUI as the JTree's UI, LooknFeel, etc. and although I did not get that ClassNotFoundException when running the program, it did not have any of the functionality that I had written ( I even wrote a System.out.println() in my MousePressed() function in MyTreeUI so that it would let me know that it is working and it never appeared). It was as if the MyTreeUI was not loaded or attached to the JTree. I also called:
    System.out.println("this is UI: " + jTree1.getUIClassID() );
    to see which UI my MyTree instantiate was using and it would printout TreeUI, not MyTreeUI. So I'm wondering what it is I'm doing wrong, I think I am very close to having this thing working but I want to know if anybody here would be able to let me know what I'm doing wrong or what would be the best way to go about implementing this Windows Explorer Multiple Selection JTree.
    Sorry for the long-winded explanation,
    -Meddev24.

  • Challenging Drag & Drop Question

    Is it possible to drag a flex component or an item in a flex
    component and drop it into _another_ flex application in a totally
    different browser window?

    Anyone have any thoughts on if this issue would be possible
    using the Flex-Ajax Bridge?
    Thanks,
    Bob I.

  • HT1267 i've got about 2500 songs on my iphone, i have replaced my computer & lost my library-question is why can't i drag/drop new downloaded music to my iphone without 'syncing' & losing my 2500 songs from the iphone?

    I've got about 2500 songs on my iphone, i have recently replaced my computer because the old one crashed, so i lost all the songs in the itunes library. My question is, it seems that now i am unable to drag/drop new downloaded songs without syncing my iphone & losing my 2500 songs from the phone?

    You cannot. Iphone will sync/manually manage music with one and only one computer at a time.  Syncing/manually managing with another will erase the current content from the iphone.
    It has always been very basic to always maintain a backup copy of your computer.  Use your backup copy to put everything back.

  • Drag and drop questions using image and painting

    Hi all,
    please apologize me if i'm posting a just discussed topic, but I couldn't find anything that could help me.
    I'm trying to create an application where I've a Jtree on the left panel that contain entities that have to be dragged and dropped in the central panel (eventually pasting a representative image) as user decide.
    I've just implemented all panels and jtree. I read java tutorial on drag and drop, but I don't know HOW i can paste image as objects that then i can manipulate in such a way that the user needs.
    Do I have to use java.awt.dnd package?
    Please, I'd like to receive some suggestion about.
    Thanks in advance for your kindness.
    Vincenzo

    I'm sorry, I think that i've not been clear in my explanation. I don't know how to transfer by drag & drop an image (a node of a jtree) to a beside panel. I don't want to get code, it will be more appreciate suggestions on how to proceede.
    I don't understand if I need java.awt.dnd package. On java tutorial I read that it shouldn't have to be used.
    Thanks, I hope that I've been clearer now.

  • .JPGs used in the drop/drag quiz questions

    In Captivate 4, can .JPGs be used in drop/drag quiz questions? We need to see if Learners can properly "build up" a sub-assembly of a machine and they will need to know which part fits on top of the correct piece of equipment.
    If not, any suggestions?

    No.  Currently no version of Captivate allows you to set up drag and drop interactions natively with images as the drag objects or targets.
    However, there are two widgets that can be purchased to do this:
    http://www.infosemantics.com.au/adobe-captivate-widgets/drag-and-drop/which-adobe-drag-and -drag-and-drop-widget-comparison
    Free trial versions of the widgets can be downloaded here if you want to try them out:
    http://www.infosemantics.com.au/adobe-captivate-widgets/download-free-trial-widgets

  • I wolud like to make a Drag&Drop JTree

    Hi everyone:
    I'm trying to implement a JTree with Drag&Drop support. I've been lookig for some code examples but It was imposible to find them. I didn't found either information about drag&drop.
    Thank you very much. Chefo

    Captivate is not really designed to do what you want in this instance.  It's more targeted at allowing a user to complete an assessment and then track whether or not they passed.  So it's only really set up to send information in a format that the LMS will understand and interpret as Pass/Faill and what the score was.
    You really need something more flexible than that. So I think you would need to get a programmer involved and have the solution custom made.  In my experience, any time you try to diverge Captivate from what it was designed to do, and you need to get other IT professionals involved, you can kiss thousands of dollars goodbye before you have a workable solution.

  • Perform drag&drop in Jtree without even selecting a node once?

    Hi All,
    Is it possible to perform drag and Drop action on tree nodes even when the Jtree is not active.
    That is, say a jtree is not active and i directly want to drag a node inside it without even selecting it once?
    Thanks alot in Advance.

    You should google for "jtree drag and drop". I remember seeing a very nice tutorial on codeproject.
    If your run into any specific issue let me know.

  • Drag and drop questions in scjp

    hi all,
    i m planning to write scjp this month..
    can anyone tell me what 'drag n drop' questions like?
    and what kind of questions are generally asked?

    Well you can't change your answer for the drag and drop i mean you can but if you try to go back and try to see your question again for drag and drop then your answer is going to be deleted and then you had to redo the whole thing.
    So i suggest please make your decision at the same time. Drag and drop are not hard i mean something like this
    System.out.printf("Pi is approxmicately", Math.PI);
    Pi is approximately ______
    Place the value for PI 3.14
    3.145
    Something like that Good luck

  • Drag and Drop Questions in ocjp6

    Hi friends, I'm about to take my ocjp6 exam the following month. Does the exam has DRAG AND DROP questions or I have no need to worry about it? Any latest exam takers? or any one who's aware of it kindly help me with your guidance friends.

    If you think that article implies that ALL drag and drop questions were removed from the tests you need to reread it.
    The fact that you are not prepared is manifest from the question that you ask and the lack of preparation that you showed by not having reviewed the official information that was available.
    As has been frequently stated in the past Oracle is always free to include or exclude ANY topic from ANY exam at ANY time without prior notice. Exam takers are expected to have knowledge in ALL of the fundamental areas of their topic.
    Most people preparing for an exam would take one of the many preparatory courses and trial exams that are available.
    The fact that you have not indicated that you have done ANY of that is what indicates your lack of preparation.
    Attempting to 'shoot the messenger' might make you feel better but it won't overcome your lack of preparation.

  • Adobe Presenter 10 Drag and Drop questions - only grey box when trying to create

    Hi,
    I try to create drag and drop questions in Presenter 10 and after clicking on Add Question -> Drag Drop, the new window opens but where I should be able to define the questions etc, the screen is just grey. Have the same issue on three other systems as well.
    Flash is updated to latest version and so is Presenter 10.
    Weirdly the installed Flash version is 15, but a right-click into the grey box shows me version 11.
    Any ideas?
    Thanks,
    Chris

    Just in case someone else has the same problem, a chat with Adobe brought the solution:
    On the gray screen, Right click and go to Global settings
    Go to advanced tab
    Scroll down and click "Trusted location settings"
    On the "Trusted location settings" window, click "add" on the bottom
    Click "Add Folder" and select "Local disk c"
    Click "Ok" and Confirm on "Trusted location settings" window
    Worked for me (on three different machines) like a charm!

  • How do I add a progress monitor to a drag and drop question in captivate 7

    I need to build a quiz. We have spent a lot of time on the style guide and appearance but I am having difficulty adding a progress monitor to my drag and drop questions. How can I do this?

    A Drag&Drop is not a normal question slide, hence that progress indicator is not added, and it wouldn't even be functional.
    Long time ago I explained how to create a custom progress indicator, maybe it can help you: Customized Progress Indicator - Captivate blog

Maybe you are looking for

  • How can I get rid of duplicate entries in iPad iCal?

    This is kind of a repeat and I apologize, but I have duplicate entries now in my iCa on my iPad because of iOS5? Others on this same topic said something about deleting the whole iPad calendar.  Before I did that, I wanted to be sure, that if I delet

  • Automatic creation of planned order in APO

    Dear Gurus, I originally posted this in PP and SD, however, it does now seem to be APO related. Hence my posting here. Can you help? This is the question: "How can we prevent that APO immediately creates a planned order when the purchase requisition

  • NET VALUE

    hello all When I try to process a sale order, the summary screen NET  VALUE (NETWR) field does not display the amount of the order. I checked up the pricing condition in the header data, the pricing condition is processed. But it does not show in the

  • Need to increase font size of header in ALV

    Hi,     I have a requirement to increase the font-size of header in the output ALV report. Also, i need to remove some of the standard icons from the output ALV using IT_EXCLUDING ?...Could any of you help me with this ?

  • Dvd player error codes -70001 & -32

    when attempting to play a dvd recv'd Error codes -7001 & -32. What do they mean?! jc