Java Swing Cursor setCursorDefault(Container cont)

Here you can find the source of setCursorDefault(Container cont)

Description

Sets the cursor to default.

License

BSD License

Parameter

Parameter Description
cont the current Window, Panel, Dialog, or other JComponent; just pass 'this', as long as it's a Container

Declaration

public static void setCursorDefault(Container cont) 

Method Source Code


//package com.java2s;
/*L//from   w w w.jav a 2s .com
 * Copyright SAIC, SAIC-Frederick.
 *
 * Distributed under the OSI-approved BSD 3-Clause License.
 * See http://ncip.github.com/caadapter/LICENSE.txt for details.
 */

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

  1. createCursor(URL url, Point hotSpot, String name)
  2. setCursor(JComponent comp, Cursor cur)
  3. setCursorBusy(JComponent component)
  4. setWaitCursor(final Component c, final boolean wait)
  5. setWaitCursor(JComponent comp)
  6. showCursor(final Cursor cursor, final Component caller, final boolean includeParent, boolean immediate)
  7. showCursor(final Cursor cursor, final Component caller, final boolean includeParent, boolean immediate)