Search |
||
The story of one "not a bug"Posted by alexfromsun on October 24, 2005 at 5:32 AM PDT
Recently I came across one interesting bug 4413412 The problem is that JLabel seems to be transparent for MouseEvents so its parent can catch mouseClick event if we click on this label. But after setting a tooltip this label stop passing MouseEvents trough and JFrame mouseListener doesn't get notified any more when we click on that label. You can check it with this little test Frame's mouse listener catches clicks from the label with no tooltip Anyway after a little investigation I closed it as not a defect. Let's see what's going on here:The most important thing that Swing or AWT specifications never tell that components should pass MouseEvents to their parents – so JLabel with tooltip works completely according to the specification, but why having tooltip changes its behavior so visibly? It's time to discover one Swing/AWT feature which I believe should be better documented: There is the only case when component is transparent for mouse events – when this component doesn't have any MouseListeners and MouseMotionListeneres attached Notice that when you do setToolTip() javax.swing.ToolTipManager adds a special MouseListener to the component to detect a moment for the tooltip to be shown. It is easy to check it using but initially JLabel doesn't have any MouseListeners – that explains why JFrame's listener gets notified when we click on the first label. Let me give some recommendations:
That's how it works Alex »
Related Topics >>
Swing Comments
Comments are listed in date ascending order (oldest first)
|
||
|
|