Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4413412
Votes 16
Synopsis Mouse Events intercepted by Tooltip
Category java:classes_swing
Reported Against 1.3
Release Fixed
State 11-Closed, Not a Defect, bug
Priority: 4-Low
Related Bugs 6534284 , 6180941 , 4769783
Submit Date 08-FEB-2001
Description


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) 
======================================================================
Posted Date : 2005-08-11 13:43:14.0
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
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
Posted Date : 2005-08-11 13:43:14.0

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

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
Posted Date : 2006-08-25 11:55:10.0
Comments
  
  Include a link with my name & email   

Submitted On 27-MAR-2001
ceckt
I have same(similer?) problem on JDK1.2.2_007.

  JPanel parent = new JPanel();
  JPanel p = new JPanel();
  p.setTooltipText("text");
  p.addMouseListener(mouseListener);
  parend.add(p);

1.mouse moved on JPanel.
2.donot wait and click on JPanel.
3.CPU used 100% 2-3 second.
4.JPanel#mouseClicked() isnot called.

BUT!
1.mouse moved on JPanel.
2.wait for Tooltip shown and disapear.
3.click on JPanel
4.JPanel#mouseClicked() is called.


Submitted On 12-SEP-2001
rdhull
It is not just MouseMotion events that are not propogated 
to the underlying panel - the same is true for all mouse 
events.


Submitted On 26-JUN-2002
rakeshkchoudhary
My GOD! No action/progress since last 15 months.


Submitted On 26-JUL-2002
adilaliasghar
Well i have checked it out on my 1.3 on windows NT 4.0 
server it works fine.


Submitted On 25-JUL-2003
Delaporte
I got the same trouble with JDK 1.4.1_02-b06.


Submitted On 07-AUG-2003
kgertsen
This is a real annoyance.  Anyone have a workaround for 
passing a mouse click to the label's parent?


Submitted On 17-SEP-2003
rgc3679
I'm having the same problem - mouse events stop after a 
setToolTipText() on a JLabel.

I voted!


Submitted On 15-DEC-2003
easdown
I too am having the same problem with 1.3.1-b24.

Peter


Submitted On 12-JAN-2005
PirolA
I need a workaround for this problem, any ideas? I could not wait  other 3 years... ;)


Submitted On 15-FEB-2005
xiarcel
I have noticed this too..



PLEASE NOTE: JDK6 is formerly known as Project Mustang