Unsets the wait (hourglass) mouse cursor for an application containing component. - Java Swing

Java examples for Swing:Mouse Event

Description

Unsets the wait (hourglass) mouse cursor for an application containing component.

Demo Code


//package com.java2s;
import java.awt.Cursor;
import java.awt.event.MouseAdapter;

import javax.swing.JComponent;

import javax.swing.RootPaneContainer;

public class Main {
    /**// w  w w .  j ava2  s . c om
     * A no-op MouseAdapter used to stop mouse input.
     */
    private static final MouseAdapter noopMouseAdapter = new MouseAdapter() {
        // nothing to see here
    };

    /**
     * Unsets the wait (hourglass) mouse cursor for an application containing <code>component</code>.
     * @param component   The component of interest.
     */
    public static void stopWaitCursor(JComponent component) {
        RootPaneContainer root = (RootPaneContainer) component
                .getTopLevelAncestor();
        root.getGlassPane().setCursor(Cursor.getDefaultCursor());
        root.getGlassPane().removeMouseListener(noopMouseAdapter);
        root.getGlassPane().setVisible(false);
    }
}

Related Tutorials