JDK-4710511 : Unexpected mouseRelease event received after calling exportAsDrag()
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.1
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2002-07-02
  • Updated: 2016-04-26
  • Resolved: 2002-09-06
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.
Other
1.4.2 mantisFixed
Related Reports
Relates :  
Description

Name: dk106046			Date: 07/02/2002

java version "1.4.1-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-rc-b15)
Java HotSpot(TM) Client VM (build 1.4.1-rc-b15, mixed mode)

and 

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


An unexpected mouseRelease event is received after calling exportAsDrag() in mousePressed processing.
This only happens on the first mouse click not subsequent clicks.

1. Run the application provided below.
   This is from http://java.sun.com/j2se/1.4/docs/guide/swing/1.4/JLabelDragNDrop.java
   with mouseReleased() method and the println() calls added.

2. Click on "Drop Here"
   mousePressed() and mouseReleased() are called. Was not expecting mouseReleased to be called.
   The following is displayed in the command prompt window.
   mousePressed
   mouseReleased
     
3. Click on "Drop Here" again.
   mousePressed() is called but mouseReleased() is correctly not called on subsequent clicks.

/*
 * Copyright 2002 Sun Microsystems, Inc. All  Rights Reserved. 
 */

// Implemented under 1.4.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

// This example demonstrates adding drag and drop (DnD)
// support to a JLabel.
public class JLabelDragNDrop {
    JFrame aFrame;
    JPanel aPanel;
    JTextField tf;
    JLabel tl;

    // Constructor
    public JLabelDragNDrop() {
        // Create the frame and container.
        aFrame = new JFrame("JLabel Drag and Drop Demo");
        aFrame.setSize(100, 10);
        aPanel = new JPanel();
        aPanel.setLayout(new GridLayout(2, 2));

        // Add the widgets.
        addWidgets();

        // Add the panel to the frame.
        aFrame.getContentPane().add(aPanel, BorderLayout.CENTER);

        // Exit when the window is closed.
        aFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // Show the panel.
        aFrame.pack();
        aFrame.setVisible(true);
    }

    // Create and add the widgets to the panel.
    private void addWidgets() {
        // Create widgets.
        tf = new JTextField(100);
        tf.setDragEnabled(true);
        tl = new JLabel("Drop Here", SwingConstants.LEFT);
        tl.setTransferHandler(new TransferHandler("text"));
        MouseListener ml = new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
                JComponent c = (JComponent)e.getSource();
                TransferHandler th = c.getTransferHandler();
System.out.println("mousePressed");
                th.exportAsDrag(c, e, TransferHandler.COPY);
            }

            public void mouseReleased(MouseEvent e) {
System.out.println("mouseReleased");
           }
        };
        tl.addMouseListener(ml);

        // Add widgets to container.
        aPanel.add(tf);
        aPanel.add(tl);

        tl.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    }

    // main method
    public static void main(String[] args) {
        // Set the look and feel.
        try {
            UIManager.setLookAndFeel(
                UIManager.getCrossPlatformLookAndFeelClassName());
        } catch(Exception e) {}

        JLabelDragNDrop example = new JLabelDragNDrop();
    }
}


======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mantis mantis-b02 FIXED IN: mantis mantis-b02 INTEGRATED IN: mantis mantis-b02 VERIFIED IN: mantis
14-06-2004

PUBLIC COMMENTS .
10-06-2004

EVALUATION Reassigining to drag&drop for the first evaluation. ###@###.### 2002-07-07 Name: dsR10078 Date: 07/08/2002 The problem looks very similar to 4613903. ###@###.### 2002-07-08 ====================================================================== Name: dsR10078 Date: 07/30/2002 Normally, while a drag operation is in progress, all mouse events are processed by the native DnD subsystem and are not passed to java. The bug manifests depending on timimgs. If a native mouse release event is not extracted from the native event queue before the drag starts, it will be consumed by the DnD subsystem, otherwise it will be posted to Java. The suggested fix for 4613903 resolves this problem: all mouse events that are on the java event queue when the drag starts are discarded. ###@###.### 2002-07-30 ======================================================================
30-07-2002