|
|
||
Alexander Potochkin's BlogOctober 2005 ArchivesThe story of one "not a bug"Posted by alexfromsun on October 24, 2005 at 05:32 AM | Permalink | Comments (8)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:
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:
| ||
|
|