JDK-4921527 : When a JList is in a JInternalFrame, a drag gesture is sometimes not recognized
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.2
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2003-09-11
  • Updated: 2005-06-08
  • Resolved: 2005-06-06
Related Reports
Duplicate :  
Description

Name: rmT116609			Date: 09/11/2003


FULL PRODUCT VERSION :
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)

java version "1.4.2_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06)
Java HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode)

FULL OPERATING SYSTEM VERSION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
If a JList is in a JInternalFrame and the JInternalFrame
is not selected, you cannot drag an item from the JList
because a drag gesture is not recognized.  Instead, you
have to click once to select the JInternalFrame, and then
click again to start the drag.  This can be seen in the
code sample below that uses code from Sheetal Gupta's
example located at
http://java.sun.com/docs/books/tutorial/dnd/sheetal.html.

REGRESSION.  Last worked in version 1.3.1

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1.  Run the attached program.
2.  Try to drag an item from the "Source Frame" to
the "Target Frame."  It won't drag.  Instead, it selects
the JInternalFrame and the JList item.
3.  Now that the JInternalFrame is selected, try to drag
the item again.  This time it works.

EXPECTED VERSUS ACTUAL BEHAVIOR :
I would expect to be able to drag an item from the JList
whether the JInternalFrame is selected or not; that was
the way it worked in 1.3.  But, this didn't happen.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
// There are 3 different files needed for this program:
// DNDComponentInterface.java, DNDList.java, and DragTest.java.
// Compile the 3 with javac, and run DragTest with java.


// Beginning of DNDComponentInterface - written by Sheetal Gupta:
// http://java.sun.com/docs/books/tutorial/dnd/sheetal.html

public interface DNDComponentInterface{
    
 public void addElement( Object s);
 public void removeElement();
   
}

// End of DNDComponentInterface



// Beginning of DNDList - written by Sheetal Gupta:
// http://java.sun.com/docs/books/tutorial/dnd/sheetal.html

/**
 * This is an example of a component, which serves as a DragSource as
 * well as Drop Target.
 * To illustrate the concept, JList has been used as a droppable target
 * and a draggable source.
 * Any component can be used instead of a JList.
 * The code also contains debugging messages which can be used for
 * diagnostics and understanding the flow of events.
 *
 * @version 1.0
 */

import java.awt.*;
import java.awt.dnd.*;
import java.awt.datatransfer.*;

import java.util.Hashtable;
import java.util.List;
import java.util.Iterator;

import java.io.*;
import java.io.IOException;

import javax.swing.JList;
import javax.swing.DefaultListModel;




public class DNDList extends JList
    implements DNDComponentInterface, DropTargetListener,DragSourceListener,
DragGestureListener    {

  /**
   * enables this component to be a dropTarget
   */

  DropTarget dropTarget = null;

  /**
   * enables this component to be a Drag Source
   */
  DragSource dragSource = null;


  /**
   * constructor - initializes the DropTarget and DragSource.
   */

  public DNDList() {
    
    dropTarget = new DropTarget (this, this);
    dragSource = new DragSource();
    dragSource.createDefaultDragGestureRecognizer( this,
DnDConstants.ACTION_MOVE, this);
  }

  /**
   * is invoked when you are dragging over the DropSite
   *
   */

  public void dragEnter (DropTargetDragEvent event) {
    
    // debug messages for diagnostics
    System.out.println( "dragEnter");
    event.acceptDrag (DnDConstants.ACTION_MOVE);
  }

  /**
   * is invoked when you are exit the DropSite without dropping
   *
   */

  public void dragExit (DropTargetEvent event) {
    System.out.println( "dragExit");
    
  }

  /**
   * is invoked when a drag operation is going on
   *
   */

  public void dragOver (DropTargetDragEvent event) {
    System.out.println( "dragOver");
  }

  /**
   * a drop has occurred
   *
   */

 
  public void drop (DropTargetDropEvent event) {
    
    try {
        Transferable transferable = event.getTransferable();
                   
        // we accept only Strings
        if (transferable.isDataFlavorSupported (DataFlavor.stringFlavor)){
        
            event.acceptDrop(DnDConstants.ACTION_MOVE);
            String s = (String)transferable.getTransferData (
DataFlavor.stringFlavor);
            addElement( s );
            event.getDropTargetContext().dropComplete(true);
        }
        else{
            event.rejectDrop();
        }
    }
    catch (IOException exception) {
        exception.printStackTrace();
        System.err.println( "Exception" + exception.getMessage());
        event.rejectDrop();
    }
    catch (UnsupportedFlavorException ufException ) {
      ufException.printStackTrace();
      System.err.println( "Exception" + ufException.getMessage());
      event.rejectDrop();
    }
  }

  /**
   * is invoked if the use modifies the current drop gesture
   *
   */
    

  public void dropActionChanged ( DropTargetDragEvent event ) {
  }

  /**
   * a drag gesture has been initiated
   *
   */
  
  public void dragGestureRecognized( DragGestureEvent event) {
    
    Object selected = getSelectedValue();
    if ( selected != null ){
        StringSelection text = new StringSelection( selected.toString());
        
        // as the name suggests, starts the dragging
        dragSource.startDrag (event, DragSource.DefaultMoveDrop, text, this);
    } else {
        System.out.println( "nothing was selected");
    }
  }

  /**
   * this message goes to DragSourceListener, informing it that the dragging
   * has ended
   *
   */

  public void dragDropEnd (DragSourceDropEvent event) {
    if ( event.getDropSuccess()){
        removeElement();
    }
  }

  /**
   * this message goes to DragSourceListener, informing it that the dragging
   * has entered the DropSite
   *
   */

  public void dragEnter (DragSourceDragEvent event) {
    System.out.println( " dragEnter");
  }

  /**
   * this message goes to DragSourceListener, informing it that the dragging
   * has exited the DropSite
   *
   */

  public void dragExit (DragSourceEvent event) {
    System.out.println( "dragExit");
    
  }

  /**
   * this message goes to DragSourceListener, informing it that the dragging
is currently
   * ocurring over the DropSite
   *
   */

  public void dragOver (DragSourceDragEvent event) {
    System.out.println( "dragExit");
    
  }

  /**
   * is invoked when the user changes the dropAction
   *
   */
   
  public void dropActionChanged ( DragSourceDragEvent event) {
    System.out.println( "dropActionChanged");
  }

  /**
   * adds elements to itself
   *
   */
   
   public void addElement( Object s ){
        (( DefaultListModel )getModel()).addElement (s.toString());
  }

  /**
   * removes an element from itself
   */
   
  public void removeElement(){
    (( DefaultListModel)getModel()).removeElement( getSelectedValue());
  }
  
}

// End of DNDList



// Beginning of DragTest

public class DragTest extends javax.swing.JFrame{

    DragTest(){
        setSize(500,500);
        javax.swing.JDesktopPane desktop = new javax.swing.JDesktopPane();
        getContentPane().add(desktop);

        javax.swing.JInternalFrame f1 = new javax.swing.JInternalFrame("Source
Frame");
        f1.setSize(200,200);
        f1.setLocation(10, 10);
        f1.setVisible(true);
        desktop.add(f1);

        javax.swing.JInternalFrame f2 = new javax.swing.JInternalFrame("Target
Frame");
        f2.setSize(200,200);
        f2.setLocation(250, 10);
        f2.setVisible(true);
        desktop.add(f2);

        DNDList sourceList = new DNDList();
        DNDList targetList = new DNDList();

        javax.swing.DefaultListModel sourceModel = new
javax.swing.DefaultListModel();
        javax.swing.DefaultListModel targetModel = new
javax.swing.DefaultListModel();

        sourceModel.addElement( "Source Item1");
        sourceModel.addElement( "Source Item2");
        sourceModel.addElement( "Source Item3");
        sourceModel.addElement( "Source Item4");
        sourceList.setModel(sourceModel);

        targetModel.addElement( "Target Item1");
        targetModel.addElement( "Target Item2");
        targetModel.addElement( "Target Item3");
        targetModel.addElement( "Target Item4");
        targetList.setModel(targetModel);

        f1.getContentPane().add(sourceList);
        f2.getContentPane().add(targetList);

        addWindowListener (new java.awt.event.WindowAdapter() {
          public void windowClosing(java.awt.event.WindowEvent e) {
            System.exit(0);
          }
        });
    }

    public static void main(String[] args) {
        new DragTest().setVisible(true);
    }
}

// End of DragTest

---------- END SOURCE ----------

CUSTOMER WORKAROUND :
We have not found a workaround.
(Incident Review ID: 166345) 
======================================================================

Comments
EVALUATION Name: dsR10078 Date: 09/11/2003 This looks like a Swing issue. ###@###.### 2003-09-12 ====================================================================== Sounds like this is due to the glass pane issues with internal frames and how we forward mouse events. This causes problems only when the internal frame is not selected, that's when the glass pane is showing. Will close a dup of mouse event forwarding bug for internal frames once I find the bug id. ###@###.### 2003-09-24 Need to investigate how drag gesture works. It may be triggered on a click rather than a press which would explain why this doesn't work with unselected internal frames. ###@###.### 2003-12-04 Reproducible on 1.6.0-ea-b37. ###@###.### 2005-05-23 18:00:03 GMT Closed. Duplicate of 4398733. ###@###.### 2005-06-06 18:06:00 GMT
04-12-2003