JDK-4468566 : Swing DnD should not use selection to show drop location
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.0,1.4.2,5.0,5.0u3,5.0u6
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS:
    generic,linux,solaris_9,windows_nt,windows_2000 generic,linux,solaris_9,windows_nt,windows_2000
  • CPU: generic,x86,sparc
  • Submitted: 2001-06-12
  • Updated: 2017-05-16
  • Resolved: 2005-06-22
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b42Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
In Swing, the selection is used to show the point where a drop operation would occur. With text components, this is the caret. In JList, JTable, JTree, the selection is used.

This causes many complications. With text, playing with the caret causes the selection to be temporary lost as described in the report below. With the other components, using the selection makes it difficult to specify a drop above or below the current selection.

A new mechanism should be designed such that a drop location can be displayed without using the selection.

-----------------------------------
Original bug report:

Name: bsC130419			Date: 06/11/2001


java version "1.4.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b65)
Java HotSpot(TM) Client VM (build 1.4.0-beta-b65, mixed mode)

Dragging selected text from a text component deselects the original text. The
original text is deselected as soon as the drag starts. I expect the original
text to remain selected until the text is dropped on a target.
Set setDragEnabled on a JTextField, JTextArea, JTextPane, JFormattedTextField
or JEditorPane to true to select default drag operation. After selecting some
text and starting to drag, the text becomes unselected.
The example code shows a frame with each of the text components in it. The
components have had their default drag operation enabled so that drag and drop
of text can by played with. Select some text in any component and drag it. As
soon as the selected text is dragged the original text becomes unselected.

/*
 * Test.java
 *
 * Created on 6 June 2001, 16:08
 */


/**
 *
 * @author  daz
 * @version 1.0
 */
public class Test extends javax.swing.JFrame {

    /** Creates new form Test */
    public Test() {
        initComponents ();
        jFormattedTextField1 = new javax.swing.JFormattedTextField();
        jFormattedTextField1.setText("jFormattedTextField1");
        getContentPane().add(jFormattedTextField1);
        jTextArea1.setDragEnabled(true);
        jTextField1.setDragEnabled(true);
        jTextPane1.setDragEnabled(true);
        jEditorPane1.setDragEnabled(true);
        jFormattedTextField1.setDragEnabled(true);
        pack ();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the FormEditor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
      jTextArea1 = new javax.swing.JTextArea();
      jTextField1 = new javax.swing.JTextField();
      jTextPane1 = new javax.swing.JTextPane();
      jEditorPane1 = new javax.swing.JEditorPane();
      
      getContentPane().setLayout(new java.awt.GridLayout(0, 1));
      
      addWindowListener(new java.awt.event.WindowAdapter() {
        public void windowClosing(java.awt.event.WindowEvent evt) {
          exitForm(evt);
        }
      });
      
      jTextArea1.setText("jTextArea1");
      getContentPane().add(jTextArea1);
      
      jTextField1.setText("jTextField1");
      getContentPane().add(jTextField1);
      
      jTextPane1.setText("jTextPanel1");
      getContentPane().add(jTextPane1);
      
      jEditorPane1.setText("jEditorPane1");
      getContentPane().add(jEditorPane1);
      
    }//GEN-END:initComponents

    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {//GEN-
FIRST:event_exitForm
        System.exit (0);
    }//GEN-LAST:event_exitForm

    /**
    * @param args the command line arguments
    */
    public static void main (String args[]) {
        new Test ().show ();
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextPane jTextPane1;
    private javax.swing.JEditorPane jEditorPane1;
    // End of variables declaration//GEN-END:variables
    private javax.swing.JFormattedTextField jFormattedTextField1;
}
(Review ID: 126245) 
======================================================================

Comments
EVALUATION Name: dsR10078 Date: 06/21/2001 Pure AWT text components are based on the native window objects: XmText and XmTextField widgets on X11, EDIT controls on Win32. All of them clear the current selection on left mouse button press. When the left mouse button is pressed we cannot predict whether the drag gesture will be eventually recognized or not, so we have to follow the default behavior and clear the current selection. The desired behavior can be implemented for Swing text components with enabled drag operation. ====================================================================== The reason that this occurs in Swing is that we use the caret to show the insert location. Ideally, we should not use the caret and use another means to show this location. By doing this we can avoid changing the selection. A similar change should be made for other components that use selection to show the insert location. I am changing the description and synopsis to reflect the source of the problem. ###@###.### 2001-11-13 See also 5077753. The behavior we decide on should likely be customized to act like the associated native platform for each L&F. ###@###.### 2004-07-23 A fix for this bug has been made! JTextComponent, JList, JTable and JTree now all have a new setDropMode(DropMode) method. This method controls how the components track and indicate their drop location. The new drop modes and the components that support them are: USE_SELECTION - JTextComponent, JList, JTable, JTree ON - JList, JTable, JTree INSERT - JTextComponent, JList, JTable, JTree INSERT_ROWS - JTable INSERT_COLS - JTable ON_OR_INSERT - JList, JTable, JTree ON_OR_INSERT_ROWS - JTable ON_OR_INSERT_COLS - JTable The default drop mode for all components will be USE_SELECTION (which uses the selection to track the drop location), for backward compatibility. However, the new drop modes offer better options for tracking and indicating the drop location, without affecting the component's selection. Each of these components will also have a new getDropLocation() method which will return a subclass of TransferHandler.DropLocation, customized to indicate the drop location as it makes sense for that component type. This getDropLocation() method is intended for use by UI code that renders the drop location. Additionally, the DropLocation will be passed to canImport, shouldIndicateAnyway, and importData of TransferHandler so that the behavior can be customized based on drop location. ###@###.### 2005-06-01 17:30:40 GMT
01-06-2005

WORK AROUND Name: bsC130419 Date: 06/11/2001 Nome ======================================================================
01-10-2004