aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Tooltip on Line2D or Rectangle2D Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Tooltip on Line2D or Rectangle2D" Watch "Tooltip on Line2D or Rectangle2D" New topic
Author

Tooltip on Line2D or Rectangle2D

Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

Ok my problem is simple, I want to display tooltip on a Line2D or Rectangle2D or Ellipse2D basically something that's not a JComponent. Can that be done??


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

I think, you have to implement the mouse motion listener class, which on mouse hover on your Rectangle object will display a tooltip frame.

HTH.


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

Like Sagar said, you need to trap mouse movements.
Also check out Line2D#contains() and Rectangle2D#contains methods.
Also check out TooltipManager#mouseXXX methods.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

[Edited the quote]
[I written it in my signature now ]
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

Ooops.
So sorry about that. Serves me right to try and reply to 3 posts and check my mails at the same time.
Corrected my original post.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

Thanks for the replies, sorry if the question is silly, this is my first encounter with a desktop application, I've worked on web applications till now.

I tried what you said, the contains method always returns false for Line2D, so I used the static Line2D.ptLineDist to find the distance of the pointer to the line, I used the mouse motion listener on the panel (as Line2D cannot have a mouse listener), and then in the mouseMoved method, I used the ptLineDist method to find if the pointer was on the line and if it was, I created a new JToolTip object and set its visibility to true, still it doesn't gets displayed. I couldn't figure out how to use ToolTipManager.mouseXXX.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

Try out this code.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

Wow that did the trick, the only change that I had to make was to set the tooltip to null outside of the rect as I didn't want tooltip outside of the rectangle. I also removed the ToolTipManager line and still its working fine, I wonder what that did

Thanks Manish and Sagar
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

Ankit Garg wrote:I also removed the ToolTipManager line and still its working fine, I wonder what that did


I had put in the line to show you how you can programatically display a tooltip.
From your original post, I got the impression you are working on some graphical manipulation utility. So I was imagining a scenario where you would want to give the user some kind of visual feedback regarding your custom shapes.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

Maneesh Godbole wrote:From your original post, I got the impression you are working on some graphical manipulation utility. So I was imagining a scenario where you would want to give the user some kind of visual feedback regarding your custom shapes.


Yes you got it absolutely right, I actually have to show the coordinates of the shapes using tooltips. Looks like I need to come out of my web app world and read a Swing book, any suggestion on a good book
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

Well I learnt java using the Core Java series by Horstmann and Cornell but then its not Swing specific.
But for you, I think the online tutorial should be sufficient.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

Hey I also have that Horstmann book, its a bit technical for beginners

And that link goes into my bookmarks, thanks
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Ankit Garg wrote:Looks like I need to come out of my web app world and read a Swing book, any suggestion on a good book

Same thing here, the only difference is I don't need the Swing book, because I really do not like to see my self building the Desktop GUI in future
Java Swing is such a vast API and difficult to play with
 
 
subject: Tooltip on Line2D or Rectangle2D
 
Similar Threads
Pop up a message
JPanel actionListener to determine click on diagonal drawLine
Problem linking button to mouse event - Please help!
Tooltip stay longer?
java.awt.Dimension