Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tooltip on Line2D or Rectangle2D

 
Ankit Garg
Sheriff
Posts: 9529
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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??
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Maneesh Godbole
Saloon Keeper
Posts: 11196
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like Sagar said, you need to trap mouse movements.
Also check out Line2D#contains() and Rectangle2D#contains methods.
Also check out TooltipManager#mouseXXX methods.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Edited the quote]
[I written it in my signature now ]
 
Maneesh Godbole
Saloon Keeper
Posts: 11196
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9529
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11196
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try out this code.
 
Ankit Garg
Sheriff
Posts: 9529
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11196
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9529
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11196
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9529
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic