> I have a JComponent, containing some other Components, including a JLabel.
> I added a MouseListener to the JComponent. But it does not react when the
[quoted text clipped - 3 lines]
>
> Andi
Am Mon, 24 Nov 2003 08:02:40 +0100 hat ak <k.andrei@gmx.de.spam>
geschrieben:
> may be you should use some kind renderer instead of labels (like JList
> does).
[quoted text clipped - 7 lines]
>> know
>> the problem?
thanks for the answer, but it doesn't help.
the problem is another annoying Swing bug:
my JLabel had a tooltip. therefore, it does not receive events!
Java Bug #4413412: Mouse Events intercepted by Tooltip
http://developer.java.sun.com/developer/bugParade/bugs/4413412.html
brougham5@yahoo.com - 25 Nov 2003 11:47 GMT
>the problem is another annoying Swing bug:
>my JLabel had a tooltip. therefore, it does not receive events!
I wouldn't be so quick to categorize that as a bug.
Look at the API docs for JLabel. I'm looking at version 1.4.2. Mine state:
:: A display area for a short text string or an image, or both. A label
:: does not react to input events. As a result, it cannot get the
:: keyboard focus. A label can, however, display a keyboard alternative
:: as a convenience for a nearby component that has a keyboard
:: alternative but can't display it.
Which part of this leads you to think that a JLabel not responding to events
is a bug? :)
ak - 25 Nov 2003 14:08 GMT
1. InputEvent and Mouseevent are different things!
2. The problem is not that label not responding, but component UNDER the
label is not responding.
> >the problem is another annoying Swing bug:
> >my JLabel had a tooltip. therefore, it does not receive events!
[quoted text clipped - 11 lines]
> Which part of this leads you to think that a JLabel not responding to events
> is a bug? :)
brougham5@yahoo.com - 25 Nov 2003 23:57 GMT
>1. InputEvent and Mouseevent are different things!
>2. The problem is not that label not responding, but component UNDER the
>label is not responding.
You're right. That's what I get for reading too quickly.
ak - 25 Nov 2003 14:13 GMT
than write your own tooltip. see example at
http://www.imagero.com/java/TreeToolTipManager.java.html.
> Am Mon, 24 Nov 2003 08:02:40 +0100 hat ak <k.andrei@gmx.de.spam>
> geschrieben:
[quoted text clipped - 18 lines]
> Java Bug #4413412: Mouse Events intercepted by Tooltip
> http://developer.java.sun.com/developer/bugParade/bugs/4413412.html
Andreas Schmidt - 25 Nov 2003 19:53 GMT
> than write your own tooltip. see example at
> http://www.imagero.com/java/TreeToolTipManager.java.html.
Thanks. I will try it!
Andi
Kleopatra - 25 Nov 2003 16:08 GMT
> the problem is another annoying Swing bug:
> my JLabel had a tooltip. therefore, it does not receive events!
>
> Java Bug #4413412: Mouse Events intercepted by Tooltip
> http://developer.java.sun.com/developer/bugParade/bugs/4413412.html
I'm not so sure that this really is a bug. The api doc for mouseEvent
states:
"A mouse action is considered to occur in a particular component if and
only if the mouse cursor is over the unobscured part of the component's
bounds when the action happens. Component bounds can be obscurred by the
visible component's children or by a menu or by a top-level window."
so mouseEvents can be expected to be propagated to the top-most (in
z-direction) visible component only. That's what happens very strictly
for heavyweight components. For lightweight comps the implementation has
a bit more leeway - the actual dispatching is done by java code which
interprets a visible child at the point of the mouseEvent as transparent
to mouseEvents as long as it does not have mouseEvents enabled, either
by having set the flag explicitely or by adding a
mouse/Motion/WheelListener to it.
Registering the child as toolTipTarget makes it "obsuring" because the
toolTipmanager registers itself as mouseListener ... That might be
annoying but should be not totally unexpected.
Assuming you really need to get the mouseEvents below a visible child, a
way out might be to not register the label with the ToolTipManager but
the panel - which then should ask it's children for a toolTip at the
mouse position (have a look at JTable it does something similar when
trying to check the renderers' tooltip)
Greetings
Jeanette
Andreas Schmidt - 25 Nov 2003 16:29 GMT
>> the problem is another annoying Swing bug:
>> my JLabel had a tooltip. therefore, it does not receive events!
[quoted text clipped - 15 lines]
>
> Assuming you really need to get the mouseEvents below a visible child, a
I don't need to get mouseEvents below a visible child
Maybe I was not clear about it: I don't actually care if the JLabel itself
receives an event. It has no listeners anyway. The annoying thing is that
the top-most container does not receive anything anymore, if the JLabel
inside has a tooltip.
I have a container that changes its state as "selected" if the user clicks
somewhere on it. Inside this container is a JLabel. So, if the user clicks
inside the container, but on the JLabel, the container does not receive
the event and cannot be "selected".
Kleopatra - 25 Nov 2003 17:29 GMT
> I don't need to get mouseEvents below a visible child
... the statement above is a contradiction to the statement below ...
> [..] The annoying thing is that
> the top-most container does not receive anything anymore,
.. because every component in a frame belongs to the container hierarchy
of the top-level container, even if there is some nesting involved.
Again: it's impossible to have _any_ component transparent for
mouseEvents if it is registered as interested in mouseEvents (which is
done implicitely by registering with the tooltipManager).
> I have a container that changes its state as "selected" if the user clicks
> somewhere on it. Inside this container is a JLabel. So, if the user clicks
> inside the container, but on the JLabel, the container does not receive
> the event and cannot be "selected".
use a glasspane over the bounds of the container to control the state.
Greetings
Jeanette
Andreas Schmidt - 25 Nov 2003 19:53 GMT
>> I don't need to get mouseEvents below a visible child
>>
[quoted text clipped - 17 lines]
>
> use a glasspane over the bounds of the container to control the state.
Okay, I can try that. But still, the "bug" about it is: I add a JLabel
without tooltip, the user can click on it and the top-level container
receives the MouseEvent when the user clicks on the JLabel. I
setToolTipText on the JLabel and the container does not receive the
MouseEvent anymore.
I understand that it might be difficult for the Swing designers to
implement the JLabel to be transparent for MouseEvents even if it is
registered with the tooltipManager. But from my application development
perspective there is an inconsistent behavior. That is, you explained why
the bug is likely to happen, but there is still no justification for it.
Andi
Kleopatra - 25 Nov 2003 23:25 GMT
> Okay, I can try that. But still, the "bug" about it is: I add a JLabel
> without tooltip, the user can click on it and the top-level container
> receives the MouseEvent when the user clicks on the JLabel.
okay that's one point of view. But in my view that "bug" is debatable: I
would not expect to ever get a mouseEvent on any component below (in
z-order) a visible component - at least not after reading the mouseEvent
api doc. So I would judge any event that does reach the lower layer as a
- maybe welcome - implementation side-effect. Maybe there is some part
of the doc that I overlooked, though.
> I understand that it might be difficult for the Swing designers to
> implement the JLabel to be transparent for MouseEvents even if it is
> registered with the tooltipManager. But from my application development
> perspective there is an inconsistent behavior. That is, you explained why
> the bug is likely to happen, but there is still no justification for it.
yeah I see your point of view - the behaviour indeed does feel
inconsistent. But IMO the reason for this discrepancy is more on the
side of being transparent at all. I don't remember any part of the doc
guaranteeing any "mouse transparency". Looking forward to learning if
there is any :-) Anyway, it's not a swing problem, the (mouse) event
dispatching behaviour is implemented in Container for all lightweight
components.
Greetings
Jeanette
Andreas Schmidt - 25 Nov 2003 20:14 GMT
>> the problem is another annoying Swing bug:
>> my JLabel had a tooltip. therefore, it does not receive events!
[quoted text clipped - 7 lines]
> mouse position (have a look at JTable it does something similar when
> trying to check the renderers' tooltip)
That sounds good, I will look at it.
It would be the same workaround I am trying for a popup menu that is
usually called from a tiny small component (20, 10), but does not receive
the focus because it has itself wider Dimensions than the small component
that calls it. So, I call the popup from within a bigger parent container.
(see
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=utf-8&threadm=opryuw8egfk0
5e3a%40News.CIS.DFN.DE&rnum=1)
Thanks, Andi