KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ca > commons > cbutil > CBButton


1 package com.ca.commons.cbutil;
2
3 import javax.swing.*;
4 import java.awt.*;
5 import java.awt.event.MouseAdapter JavaDoc;
6 import java.awt.event.MouseEvent JavaDoc;
7
8
9 /**
10  * Simple class that extends JButton to give the button the affact of a rollover.
11  * On mouse entered, the text changes colour to blue.
12  *
13  * @author Trudi.
14  */

15
16 public class CBButton extends JButton
17 {
18
19
20     /**
21      * Constructor that calls CBButton(String text, String tooltip, Icon icon) with a null icon.
22      *
23      * @param text the button label.
24      * @param tooltip the button tooltip.
25      */

26
27     public CBButton(String JavaDoc text, String JavaDoc tooltip)
28     {
29         this(text, tooltip, null);
30     }
31
32
33     /**
34      * Constructor that calls CBButton(String text, String tooltip, Icon icon) with a null icon.
35      *
36      * @param text the button label.
37      * @param icon the icon to put on the button.
38      */

39
40     public CBButton(String JavaDoc text, Icon icon)
41     {
42         this(text, "", icon);
43     }
44
45
46     /**
47      * Constructor that makes the button. It adds the tooltip and a mouse listener
48      * to create the rollover affect.
49      *
50      * @param text the button label.
51      * @param tooltip the button tooltip.
52      * @param icon the icon to put on the button.
53      */

54
55     public CBButton(String JavaDoc text, String JavaDoc tooltip, Icon icon)
56     {
57         super(text, icon);
58
59         if (tooltip != null)
60             setToolTipText(tooltip);
61
62         addMouseListener(new MouseAdapter JavaDoc()
63         {
64             public void mouseEntered(MouseEvent JavaDoc e)
65             {
66                 setForeground(Color.blue);
67             }
68
69             public void mouseExited(MouseEvent JavaDoc e)
70             {
71                 setForeground(Color.black);
72             }
73         });
74     }
75 }
76
Popular Tags