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

Creating a new component under cursor does not fire mouseEntered()

XMLWordPrintable

    • Cause Known
    • x86
    • windows_2000

      Name: ssT124754 Date: 02/28/2001



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

      Creating a GUI component under the cursor does not fire the mouseEntered()
      trigger on the MouseListeners of this new component directly. The trigger
      does fire however, when the mouse is moved. I would understand if the
      trigger does not fire at all, but too late is unacceptable.
      Below is an example illustrating this problem: click on the label to
      produce a new instance of the label. I tried to find this bug in the Sun bug
      database, and the nearest hit I could find is bug report 4027025 (Creating a
      new component under cursor causes me to lose mouse motion events) with
      status "Closed, not reproducable"
      The code contains a bonus bug: uncommenting the comment and the text will be
      displayed over previous text.

      Greetings,

      Mark Scheffer.

      /* TestMouseMove 1.0 2001/02/21 */

      import javax.swing.*;
      import java.awt.event.*;
      import javax.swing.event.*;

      public class TestMouseMove extends MouseInputAdapter {

          public static void main(java.lang.String[] args) {
      new TestMouseMove();
          }

          JFrame f;
          JPanel p = new JPanel();
          JLabel label;

          public TestMouseMove() {

              f = new JFrame();
              f.setContentPane(p);
              newButton();
              f.pack();
      f.setVisible(true);
          }

          public void newButton() {
              label = new JLabel("Not on label");
              label.addMouseListener(this);
              label.addMouseMotionListener(this);
              p.removeAll();
              p.add(label);
              p.revalidate();
      //f.setContentPane(label);
          }

          public void mousePressed(MouseEvent e) {
              label.setText("New label...");
          }

          public void mouseReleased(MouseEvent e) {
              newButton();
          }

          public void mouseEntered(MouseEvent e) {
              System.out.println("ENTER");
              label.setText("On label");
          }
       
          public void mouseExited(MouseEvent e) {
              System.out.println("EXIT");
              label.setText("Not on label");
          }
          
          public void mouseDragged(MouseEvent e) { }
          public void mouseMoved(MouseEvent e) { }
      }
      /* end */
      (Review ID: 117431)
      ======================================================================

            dav Andrei Dmitriev (Inactive)
            ssultanasunw Shaheen Sultana (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: