Hello,
I just wrote a simple Java 2D based component to display
geometrical entities. On some off them I want to display a tooltip.
In the Tcl/Tk canvas I would bind the mouse enter event for the
items, but what is the prefered solution in Java 2D ?
My current solution is based on the bounding boxes of the GeneralPath,
but does not work that smooth. As the items are pretty small,
an offset is needed to enable picking.
But the bounding box + offset does not work, as the bounding box of the
interesiting items may overlap.
Any tips appreciated, Carsten
Tomba - 22 Aug 2005 10:43 GMT
> Hello,
>
[quoted text clipped - 10 lines]
>
> Any tips appreciated, Carsten
I have kind of the same problem. I must draw several splines and
rectangles in a canvas, but then every item must be clickable.
I would like any tips how I should check whether a mouse click selects a
drawn item or just doesn't need any action...
thanks in advance - too ;)
Thomas Hawtin - 22 Aug 2005 13:24 GMT
> Hello,
>
[quoted text clipped - 8 lines]
> But the bounding box + offset does not work, as the bounding box of the
> interesiting items may overlap.
I suggest overriding JComponent.getToolTipText(MouseEvent). Use
Shape.contains (GeneralPath implements Shape) to find which object to pick.
If you are using separate components for each shape (which may not be
particularly efficient), then override JComponent.contains instead.
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/