Java Swing Cursor waitCursorOff(Component comp)

Here you can find the source of waitCursorOff(Component comp)

Description

Turns the waits cursor off.

License

Apache License

Parameter

Parameter Description
comp Component that can be used to determine the glass pane

Declaration

public static void waitCursorOff(Component comp) 

Method Source Code

//package com.java2s;
/*/* w  w  w.  j av  a 2 s.  c om*/
 *   Copyright 2007 skynamics AG
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */

import java.awt.Component;

import java.awt.Cursor;

import javax.swing.JRootPane;

import javax.swing.SwingUtilities;

public class Main {
    /** Saves the current visible status of the glass pane visible for {@link #waitCursorOn} */
    private static boolean glassPaneVisible;
    /** Saves the current cursor status of the glass pane visible for {@link #waitCursorOn} */
    private static Cursor glassPaneCursor;

    /**
     * Turns the waits cursor off.
     * This will reset the changes to the glass pane caused by a call to {@link #waitCursorOn}.
     * If there is not information present about the previous state of the glass pane
     * (i. e. because waitCursorOff has already been called), the method will do nothing.
     *
     * @param comp Component that can be used to determine the glass pane
     */
    public static void waitCursorOff(Component comp) {
        // Reset the status of the glass pane if reset info present
        if (glassPaneCursor != null) {
            Component gp = getGlassPane(comp);

            gp.setVisible(glassPaneVisible);
            gp.setCursor(glassPaneCursor);

            glassPaneVisible = false;
            glassPaneCursor = null;
        }
    }

    /**
     * Returns the GlassPane that belongs to a given Component. Throws
     * an IllegalArgumentException if comp has no RootPaneContainer-ancestor
     * or is null.
     *
     * @param comp Component
     * @return The glass pane
     */
    public static Component getGlassPane(Component comp) {
        JRootPane root = SwingUtilities.getRootPane(comp);

        if (root == null) {
            throw new IllegalArgumentException("Component must be descendant of RootPaneContainer");
        }

        return root.getGlassPane();
    }
}

Related

  1. showDefaultCursor()
  2. showDefaultCursorOnWindow(Component caller)
  3. showDefaultCursorOnWindow(Component caller)
  4. startWaitCursor(JComponent component)
  5. startWaitCursor(JComponent component)