cbbutton.java

来自「JAVA开源LDAP浏览器jxplorer的源码!」· Java 代码 · 共 76 行

JAVA
76
字号
package com.ca.commons.cbutil;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;


/**
 * Simple class that extends JButton to give the button the affact of a rollover.
 * On mouse entered, the text changes colour to blue.
 *
 * @author Trudi.
 */

public class CBButton extends JButton
{


    /**
     * Constructor that calls CBButton(String text, String tooltip, Icon icon) with a null icon.
     *
     * @param text    the button label.
     * @param tooltip the button tooltip.
     */

    public CBButton(String text, String tooltip)
    {
        this(text, tooltip, null);
    }


    /**
     * Constructor that calls CBButton(String text, String tooltip, Icon icon) with a null icon.
     *
     * @param text the button label.
     * @param icon the icon to put on the button.
     */

    public CBButton(String text, Icon icon)
    {
        this(text, "", icon);
    }


    /**
     * Constructor that makes the button.  It adds the tooltip and a mouse listener
     * to create the rollover affect.
     *
     * @param text    the button label.
     * @param tooltip the button tooltip.
     * @param icon    the icon to put on the button.
     */

    public CBButton(String text, String tooltip, Icon icon)
    {
        super(text, icon);

        if (tooltip != null)
            setToolTipText(tooltip);

        addMouseListener(new MouseAdapter()
        {
            public void mouseEntered(MouseEvent e)
            {
                setForeground(Color.blue);
            }

            public void mouseExited(MouseEvent e)
            {
                setForeground(Color.black);
            }
        });
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?