add Click Tip Effect - Java Swing

Java examples for Swing:JTooltip

Description

add Click Tip Effect

Demo Code


//package com.java2s;

import java.awt.event.MouseEvent;

import javax.swing.JComponent;

public class Main {
    public static void addClickTipEffect(final JComponent component) {
        component.setForeground(new java.awt.Color(51, 51, 255));
        component//  w w w.j  a va2 s  .c  o  m
                .setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        component.addMouseListener(new java.awt.event.MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
                component.setOpaque(true);
                component.setBackground(new java.awt.Color(51, 51, 255));
                component.setForeground(new java.awt.Color(255, 255, 255));
            }

            @Override
            public void mouseExited(MouseEvent e) {
                component.setOpaque(false);
                component.setBackground(new java.awt.Color(255, 255, 255));
                component.setForeground(new java.awt.Color(51, 51, 255));
            }
        });
    }
}

Related Tutorials