1 19 20 package com.izforge.izpack.gui; 21 22 import java.awt.Color ; 23 import java.awt.event.MouseAdapter ; 24 import java.awt.event.MouseEvent ; 25 26 import javax.swing.Action ; 27 import javax.swing.Icon ; 28 import javax.swing.JButton ; 29 30 35 public class HighlightJButton extends JButton 36 { 37 38 private static final long serialVersionUID = 3833184718324969525L; 39 40 46 HighlightJButton(Icon icon, Color color) 47 { 48 super(icon); 49 initButton(color); 50 } 51 52 58 HighlightJButton(String text, Color color) 59 { 60 super(text); 61 initButton(color); 62 } 63 64 71 HighlightJButton(String text, Icon icon, Color color) 72 { 73 super(text, icon); 74 initButton(color); 75 } 76 77 83 HighlightJButton(Action a, Color color) 84 { 85 super(a); 86 initButton(color); 87 } 88 89 94 protected void initButton(Color highlightColor) 95 { 96 this.highlightColor = highlightColor; 97 defaultColor = getBackground(); 98 99 addMouseListener(new MouseHandler()); 100 } 101 102 107 public void setEnabled(boolean b) 108 { 109 reset(); 110 super.setEnabled(b); 111 } 112 113 114 protected void reset() 115 { 116 setBackground(defaultColor); 117 } 118 119 120 protected Color highlightColor; 121 122 123 protected Color defaultColor; 124 125 130 private class MouseHandler extends MouseAdapter 131 { 132 133 138 public void mouseEntered(MouseEvent e) 139 { 140 if (isEnabled()) setBackground(highlightColor); 141 } 142 143 148 public void mouseExited(MouseEvent e) 149 { 150 if (isEnabled()) setBackground(defaultColor); 151 } 152 } 153 } 154 | Popular Tags |