Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to do a Mouseover..

 
Rocky Summers
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm curious... is there any way i can add a "Mouseover" to a JLabel so that when the mouse is over it, the cursor changes to a hand-cursor?
Thanks,
Rock
 
Lalit K Kumar
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I think you can add a "mouseover" on a jlabel. To do so you will have to implement "MouseListener" class.Then to the respective label add the listener (.addMouseListener) and implement the required methods ("mouseOver" in your case).
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ummm... actually the interface you want to look at is MouseMotionListener... and the method you'll want to use is mouseMoved(). You could also try setting a boolean in mouseEntered() and unsetting it in mouseExited() of the MouseListener interface.

You could also use a JButton instead of a JLabel and use the built in methods - setRolloverEnabled(), setRolloverIcon(), etc.
 
Brian Pipa
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do this. Add a mouseListener to a JLabel and change the cursor on mouseEntered and mouseExited.
I have a custom class that does just this - if anyone wants to see the code, let me know.
Brian
 
Rocky Summers
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brian I do!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic