Here you can find the source of decorateComponentWithMouseOverCursorChange(final JComponent toDecorate, final int mouseEntered, final int mouseExited)
Parameter | Description |
---|---|
toDecorate | DOCUMENT ME! |
mouseEntered | DOCUMENT ME! |
mouseExited | DOCUMENT ME! |
public static MouseListener decorateComponentWithMouseOverCursorChange(final JComponent toDecorate, final int mouseEntered, final int mouseExited)
//package com.java2s; //License from project: LGPL import java.awt.Cursor; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.JComponent; public class Main { /**/* w w w. ja v a2 s . c o m*/ * Adds a mouse listener to the given component, so that the cursor will change on mouse entered/exited. * * <p>Hint: Uses the awt.Cursor.XXX constants!</p> * * @param toDecorate DOCUMENT ME! * @param mouseEntered DOCUMENT ME! * @param mouseExited DOCUMENT ME! * * @return the listener that was added */ public static MouseListener decorateComponentWithMouseOverCursorChange(final JComponent toDecorate, final int mouseEntered, final int mouseExited) { final MouseListener toAdd = new MouseAdapter() { private final Cursor entered = new Cursor(mouseEntered); private final Cursor exited = new Cursor(mouseExited); @Override public void mouseEntered(final MouseEvent e) { if (toDecorate.isEnabled()) { toDecorate.setCursor(entered); } } @Override public void mouseExited(final MouseEvent e) { if (toDecorate.isEnabled()) { toDecorate.setCursor(exited); } } }; toDecorate.addMouseListener(toAdd); return toAdd; } }