Java Utililty Methods Swing Cursor

List of utility methods to do Swing Cursor

Description

The list of methods to do Swing Cursor are organized into topic(s).

Method

CursorcreateCursor(URL url, Point hotSpot, String name)
create Cursor
return createCursor(new ImageIcon(url), hotSpot, name);
voidsetCursor(JComponent comp, Cursor cur)
Sets the mouse cursor for a component
comp.setCursor(cur);
Component parent = comp.getParent();
while (parent != null) {
    parent = parent.getParent();
    if (parent != null)
        parent.setCursor(cur);
voidsetCursorBusy(JComponent component)
Set cursor to busy and disable application input.
JDialog dialog = findContainingDialog(component);
if (dialog != null) {
    setCursorBusy(dialog);
} else {
    JFrame frame = findContainingFrame(component);
    if (frame != null) {
        setCursorBusy(frame);
voidsetCursorDefault(Container cont)
Sets the cursor to default.
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();
...
voidsetWaitCursor(final Component c, final boolean wait)
Toggles the cursor for the given component and all child components between the wait cursor and the normal one.
setCursor(c, wait ? Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR) : null);
voidsetWaitCursor(JComponent comp)
Sets the wait mouse cursor for this component
setCursor(comp, new Cursor(Cursor.WAIT_CURSOR));
voidshowCursor(final Cursor cursor, final Component caller, final boolean includeParent, boolean immediate)
show Cursor
if (caller == null)
    return;
Runnable r = () -> {
    caller.setCursor(cursor);
    if (includeParent) {
        final Window w = getWindowAncestor(caller);
        if (w != null) {
            w.setCursor(cursor);
...
voidshowCursor(final Cursor cursor, final Component caller, final boolean includeParent, boolean immediate)
show Cursor
if (caller == null)
    return;
Runnable r = new Runnable() {
    @Override
    public void run() {
        caller.setCursor(cursor);
        if (includeParent) {
            final Window w = getWindowAncestor(caller);
...
voidshowDefaultCursor()
Sets cursor for specified component to normal cursor
_root.getGlassPane().setCursor(Cursor.getDefaultCursor());
_root.getGlassPane().removeMouseListener(_mouseAdapter);
_root.getGlassPane().setVisible(false);
voidshowDefaultCursorOnWindow(Component caller)
show Default Cursor On Window
showDefaultCursor(caller, true);