Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4710511

Unexpected mouseRelease event received after calling exportAsDrag()

    XMLWordPrintable

Details

    • mantis
    • x86
    • windows_2000
    • Verified

    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();
          }
      }


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

      Attachments

        Issue Links

          Activity

            People

              dassunw Das Das (Inactive)
              dkorbel David Korbel (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: