The moose likes Swing / AWT / SWT and the fly likes How to do a Mouseover.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to do a Mouseover.." Watch "How to do a Mouseover.." New topic

How to do a Mouseover..

Rocky Summers
Ranch Hand

Joined: Nov 07, 2003
Posts: 66
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?
Lalit K Kumar
Ranch Hand

Joined: Jan 29, 2004
Posts: 32
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

Joined: Oct 18, 2000
Posts: 4121

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.

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Brian Pipa
Ranch Hand

Joined: Sep 29, 2003
Posts: 299
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.

My Java Freeware:<br />MACCC - <a href="" target="_blank" rel="nofollow"></a><br />Nator - <a href="" target="_blank" rel="nofollow"></a>
Rocky Summers
Ranch Hand

Joined: Nov 07, 2003
Posts: 66
Brian I do!
I agree. Here's the link:
subject: How to do a Mouseover..
It's not a secret anymore!