Java Swing Cursor startWaitCursor(JComponent component)

Here you can find the source of startWaitCursor(JComponent component)

Description

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

License

LGPL

Parameter

Parameter Description
component The component to block.

Declaration

public static void startWaitCursor(JComponent component) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.awt.Cursor;
import java.awt.event.MouseAdapter;

import javax.swing.JComponent;

import javax.swing.RootPaneContainer;

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

    /**
     * Sets the wait (hourglass) mouse cursor for an application containing <code>component</code>.
     * @param component   The component to block.
     */
    public static void startWaitCursor(JComponent component) {
        RootPaneContainer root = (RootPaneContainer) component.getTopLevelAncestor();
        root.getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        root.getGlassPane().addMouseListener(noopMouseAdapter);
        root.getGlassPane().setVisible(true);
    }
}

Related

  1. showCursor(final Cursor cursor, final Component caller, final boolean includeParent, boolean immediate)
  2. showDefaultCursor()
  3. showDefaultCursorOnWindow(Component caller)
  4. showDefaultCursorOnWindow(Component caller)
  5. startWaitCursor(JComponent component)
  6. waitCursorOff(Component comp)