Created
November 12, 2012 07:03
-
-
Save TabsPH/4057899 to your computer and use it in GitHub Desktop.
Hover event for such components like JButton and JLabel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.Color; | |
import java.awt.event.MouseAdapter; | |
import java.awt.event.MouseEvent; | |
import javax.swing.JLabel; | |
public class Hover extends MouseAdapter { | |
private String lblStr = ""; | |
public Hover( String lblStr ) { | |
this.lblStr = lblStr; | |
} | |
@Override | |
public void mouseEntered(MouseEvent e) { | |
JLabel lbl = (JLabel) e.getComponent(); | |
lbl.setForeground(new Color(255, 127, 80)); | |
lbl.setText( String.format( "<html><u>%s</u></html>", lblStr) ); | |
} | |
@Override | |
public void mouseExited(MouseEvent e) { | |
JLabel lbl = (JLabel) e.getComponent(); | |
lbl.setText( String.format( "<html><u>%s</u><</html>", lblStr ) ); | |
lbl.setForeground( new Color(245, 245, 245) ); | |
} | |
} |
Thanks
Thanks)
Searching for a while thanks for your post i have found a way to work with my own using yours as reference
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks.