• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Event Handlers:Mouse over "circles"

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a short example of how to use multiple tooltips on components that generate graphics... enjoy!

 
Hey! You're stepping on my hand! Help me tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic