JDK-4413412 : Mouse Events intercepted by Tooltip
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.3.0,6
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_nt,windows_xp
  • CPU: x86
  • Submitted: 2001-02-08
  • Updated: 2006-08-25
  • Resolved: 2006-08-25
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 7
7Resolved
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
Name: yyT116575			Date: 02/08/2001


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

When you add a tooltip to a JLabel, you no longer can listen for MouseMotion
events in any Container behind that JLabel.  For example, I added a JLabel to
the JFrame and added a MouseMotionListener to the JFrame.  The JFrame sees the
MouseMotion events even when you move across the label.  The minute you add a
tooltip to the JLabel, the MouseMotion events are not propogated to the JFrame.

The bug report #4234237 incorrectly closed this as not reproducible.  Their
code added the listener to the label, not the JFrame or JPanel.

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

public class MyFrame extends JFrame {

  public MyFrame() {
    JLabel l1 = new JLabel("This is my label");

    /* comment out following line, then MouseEvent will be triggered
     * but not tooltip shows up.
     */
    l1.setToolTipText("tooltip1");

    this.addMouseMotionListener(new MouseMotionListener(){
      public void mouseDragged(MouseEvent e){
        System.out.println("Dragged " + e.getX() + " " + e.getY());
      }
      public void mouseMoved(MouseEvent e){
        System.out.println("Moved "  + e.getX() + " " + e.getY());
      }
    });

    getContentPane().add(l1, BorderLayout.SOUTH);
    setSize(200,200);
    setVisible(true);
  }

  public static void main(String args[]){
    MyFrame m = new MyFrame();
  }
}
(Review ID: 116608) 
======================================================================

Comments
EVALUATION This is not bug To catch mouseEvents for particuar component you shoud attach a listener to this component (to the JLabel from test case) For more details please see "http://download.java.net/javadesktop/blogs/alexfromsun/2006.06.28/BOF-0204.pdf" "MouseEvents" section
25-08-2006

EVALUATION Contribution forum : https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?forumID=1463&messageID=14940
22-08-2006

WORK AROUND Add MouseMoutionListener to all components which should listen such events or Use GlassPane getGlassPane().setVisible(true); getGlassPane().addMouseMotionListener(new MouseMotionListener(){ public void mouseDragged(MouseEvent e){ System.out.println("Dragged " + e.getX() + " " + e.getY()); } public void mouseMoved(MouseEvent e){ System.out.println("Moved " + e.getX() + " " + e.getY()); } }); But in this glass pane only will recieve mouse events other components won't, so first solution is more preferable
11-08-2005

EVALUATION That is how it works: initially JLabel doesn't have any MouseMotionListeners and in this case delegates all mouse events to its parent. Thats why you can see frame listener works. This is undocumented behaviour and it is not recommended to rely on it Setting a tool tip internally adds a MouseMotionListener to the label and stops delegating mouse events to the frame. See "workaround" section
11-08-2005