This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Event Handlers:Mouse over "circles"

 
Sanjit Singh
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,
I am a beginner with Swing and I have to complete a project that is due soon. So I would be grateful if somebody could help me out.
I basically have a JFrame and a JPanel inside it to draw a few lines and circles. I am making a time graph inside the JPanel using raw x and y coordinates. I want to achieve the following:
1.I want to draw a small circle at the point where two lines meet.
2.I would also like to have a small pop up box with a message inside it when the user brings his mouse over this circle. I would not like to have a JOptionPane but instead a small window as I have lots of text (multiple lines)to display. When the user moves his mouse away from this circle, then the message box should close automatically.
I have already done point 1. by having a
public void paintComponent(Graphics g)
method in which I am using the graphics object to draw lines and circles.
PROBLEM: My main problem is in point 2, where I would like to add mouse listeners to this circle and somehow to implement this pop box. How can I achieve this? Can I have event handlers on a "circle" and that also inside the paintComponent method? Which swing component should I use for the popup window and how can I use it for my purpose?
Any help in this regard (sample code)would be highly appreciated. Thanks in advance!
Sanjit
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a short example of how to use multiple tooltips on components that generate graphics... enjoy!

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic