Sets the cursor to default. - Java Swing

Java examples for Swing:Cursor

Description

Sets the cursor to default.

Demo Code

/*L/*from   w ww.ja va2s .  c  om*/
 * Copyright SAIC, SAIC-Frederick.
 *
 * Distributed under the OSI-approved BSD 3-Clause License.
 * See http://ncip.github.com/caadapter/LICENSE.txt for details.
 */
//package com.java2s;
import javax.swing.*;
import java.awt.*;

public class Main {
    /**
     * Sets the cursor to default.  Should be called AFTER time-intensive task has finished.
     * Re-enables the mouse pointer for the current window.
     *
     * @param cont the current Window, Panel, Dialog, or other JComponent;
     *             just pass 'this', as long as it's a Container
     */
    public static void setCursorDefault(Container cont) {
        if (cont == null) {
            System.err
                    .println("setCursorDefault(Container cont): Container argument cannot be null. Will return and do nothing.");
            return;
        }

        Component glasspane = null;

        if (cont instanceof RootPaneContainer) {
            glasspane = ((RootPaneContainer) cont).getGlassPane();
        } else if (cont instanceof JComponent) {
            glasspane = ((JComponent) cont).getRootPane().getGlassPane();
        }

        Window window = SwingUtilities.windowForComponent(glasspane);
        window.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        glasspane.setVisible(false);
    }
}

Related Tutorials