User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 428,199 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,203 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting

Creating Hover Effect for JButton

Join Date: May 2007
Location: USA
Posts: 2,857
Reputation: Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all Ezzaral is a name known to all 
Rep Power: 12
Solved Threads: 283
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Maven

Re: Creating Hover Effect for JButton

  #4  
May 13th, 2008
You can do whatever you want when the mouse enters or leaves the button
  1. jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
  2. public void mouseEntered(java.awt.event.MouseEvent evt) {
  3. jButton1.setBackground(Color.GREEN);
  4. }
  5. public void mouseExited(java.awt.event.MouseEvent evt) {
  6. jButton1.setBackground(UIManager.getColor("control"));
  7. }
  8. });
or to just underline
  1. jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
  2. Font originalFont = null;
  3.  
  4. public void mouseEntered(java.awt.event.MouseEvent evt) {
  5. originalFont = jButton1.getFont();
  6. Map attributes = originalFont.getAttributes();
  7. attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
  8. jButton1.setFont(originalFont.deriveFont(attributes));
  9. }
  10.  
  11. public void mouseExited(java.awt.event.MouseEvent evt) {
  12. jButton1.setFont(originalFont);
  13. }
  14. });
Reply With Quote  
All times are GMT -4. The time now is 3:09 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC