Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5847409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:42:52+00:00 2026-05-22T12:42:52+00:00

I am having issues displaying a wait cursor in my application. Whenever the mouse

  • 0

I am having issues displaying a wait cursor in my application. Whenever the mouse is above a panel that defines its own cursor, the wait cursor does not appear. If a panel does not change the cursor, the wait cursor appears.

I am attaching a SSCE to accurately explain my problem.

public class BusyCursorTest extends javax.swing.JFrame {

public BusyCursorTest() {

    javax.swing.JMenuBar menuBar = new javax.swing.JMenuBar();
    javax.swing.JMenu menu = new javax.swing.JMenu("Menu");
    javax.swing.JMenuItem wait1 = new javax.swing.JMenuItem("Wait 100 ms");
    javax.swing.JMenuItem wait2 = new javax.swing.JMenuItem("Wait 250 ms");
    javax.swing.JMenuItem wait3 = new javax.swing.JMenuItem("Wait 500 ms");
    javax.swing.JMenuItem wait4 = new javax.swing.JMenuItem("Wait 1000 ms");
    menu.add(wait1);
    menu.add(wait2);
    menu.add(wait3);
    menu.add(wait4);
    menuBar.add(menu);
    setJMenuBar(menuBar);
    wait1.addActionListener(getActionListener(this, delayActionListener(100)));
    wait2.addActionListener(getActionListener(this, delayActionListener(250)));
    wait3.addActionListener(getActionListener(this, delayActionListener(500)));
    wait4.addActionListener(getActionListener(this, delayActionListener(1000)));

    cursorPanel = new javax.swing.JPanel();
    cursorPanel.addMouseListener(new java.awt.event.MouseAdapter() {

        public void mouseEntered(java.awt.event.MouseEvent e) {
            cursorPanel.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.CROSSHAIR_CURSOR));
        }

        public void mouseExited(java.awt.event.MouseEvent e) {
            cursorPanel.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
        }

    });

    javax.swing.JTabbedPane tabbedPane = new javax.swing.JTabbedPane();
    tabbedPane.addTab("Default", new javax.swing.JPanel());
    tabbedPane.addTab("Cursor change", cursorPanel);
    getContentPane().add(tabbedPane);

    setTitle("Cursor test");
    setSize(400, 400);
    setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
    setVisible(true);
}

private java.awt.event.ActionListener delayActionListener(final int delay) {
    java.awt.event.ActionListener listener = new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent ae) {
            try {
                Thread.sleep(delay);
            } catch (InterruptedException e) {
            }
        }

    };
    return listener;
}

public static void main(String[] args) {
    new BusyCursorTest();
}

public static java.awt.event.ActionListener getActionListener(final java.awt.Component component,
    final java.awt.event.ActionListener originalActionListener) {

    java.awt.event.ActionListener actionListener = new java.awt.event.ActionListener() {

        public void actionPerformed(final java.awt.event.ActionEvent e) {

            java.util.TimerTask timerTask = new java.util.TimerTask() {

                public void run() {
                    originalCursor = component.getCursor();
                    component.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
                }

            };
            java.util.Timer timer = new java.util.Timer();

            try {
                timer.schedule(timerTask, DELAY_MS);
                originalActionListener.actionPerformed(e);
            } finally {
                timer.cancel();
                component.setCursor(originalCursor);
            }
        }

    };
    return actionListener;
}

private javax.swing.JPanel cursorPanel = null;

public static java.awt.Cursor originalCursor = null;

public static final int DELAY_MS = 250;
}

Run the attached SSCE.

When the first tab (“Default”) is selected, clicking on the 1000ms menu item will show the busy cursor.

When the second tab (“Cursor change”) is selected, clicking on the 1000ms menu item does not show the busy cursor.

How should I remedy this problem?

I would strongly prefer that my code do not have to take into account any of the panels, as it is immensely difficult for me keep track of which panels may be at the forefront. Also, the events are not always generated due to a mouse click.

What is the recommended workaround so that I can modify the behavior at the top-level container?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:42:53+00:00Added an answer on May 22, 2026 at 12:42 pm

    After searching the internet, I found the answer to my question.

    The key is to set the cursor on the glasspane of the frame that contains the component which wants to display a busy cursor. I got the idea from the following articles on the net.

    Wait, Cursor, Wait!

    An Automatic Wait Cursor: WaitCursorEventQueue

    I modified my SSCE to make it work for the case when components inside the frame set their own cursor. Here is the modified SSCE.

    public class BusyCursorTest extends javax.swing.JFrame {
    
    private javax.swing.JPanel cursorPanel = null;
    
    public BusyCursorTest() {
    
        javax.swing.JMenuBar menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu menu = new javax.swing.JMenu("Menu");
        javax.swing.JMenuItem wait1 = new javax.swing.JMenuItem("Wait 100 ms");
        javax.swing.JMenuItem wait2 = new javax.swing.JMenuItem("Wait 250 ms");
        javax.swing.JMenuItem wait3 = new javax.swing.JMenuItem("Wait 500 ms");
        javax.swing.JMenuItem wait4 = new javax.swing.JMenuItem("Wait 1000 ms");
        menu.add(wait1);
        menu.add(wait2);
        menu.add(wait3);
        menu.add(wait4);
        menuBar.add(menu);
        setJMenuBar(menuBar);
        wait1.addActionListener(getActionListener(this, delayActionListener(100)));
        wait2.addActionListener(getActionListener(this, delayActionListener(250)));
        wait3.addActionListener(getActionListener(this, delayActionListener(500)));
        wait4.addActionListener(getActionListener(this, delayActionListener(1000)));
    
        cursorPanel = new javax.swing.JPanel();
        cursorPanel.addMouseListener(new java.awt.event.MouseAdapter() {
    
            public void mouseEntered(java.awt.event.MouseEvent e) {
                cursorPanel.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.CROSSHAIR_CURSOR));
            }
    
            public void mouseExited(java.awt.event.MouseEvent e) {
                cursorPanel.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
            }
    
        });
    
        javax.swing.JTabbedPane tabbedPane = new javax.swing.JTabbedPane();
        tabbedPane.addTab("Default", new javax.swing.JPanel());
        tabbedPane.addTab("Cursor change", cursorPanel);
        getContentPane().add(tabbedPane);
    
        setTitle("Cursor test");
        setSize(400, 400);
        setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
        setVisible(true);
    }
    
    private java.awt.event.ActionListener delayActionListener(final int delay) {
        java.awt.event.ActionListener listener = new java.awt.event.ActionListener() {
    
            public void actionPerformed(java.awt.event.ActionEvent ae) {
                try {
                    Thread.sleep(delay);
                } catch (InterruptedException e) {
                }
            }
    
        };
        return listener;
    }
    
    public static void main(String[] args) {
        new BusyCursorTest();
    }
    
    public static java.awt.event.ActionListener getActionListener(final javax.swing.JFrame frame,
        final java.awt.event.ActionListener originalActionListener) {
    
        java.awt.event.ActionListener actionListener = new java.awt.event.ActionListener() {
    
            public void actionPerformed(final java.awt.event.ActionEvent e) {
    
                java.util.TimerTask timerTask = new java.util.TimerTask() {
    
                    public void run() {
                        originalCursor = frame.getCursor();
                        startWaitCursor(frame);
                    }
    
                };
                java.util.Timer timer = new java.util.Timer();
    
                try {
                    timer.schedule(timerTask, DELAY_MS);
                    originalActionListener.actionPerformed(e);
                } finally {
                    timer.cancel();
                    stopWaitCursor(frame);
                }
            }
    
        };
        return actionListener;
    }
    
    private static void startWaitCursor(javax.swing.JFrame frame) {
        frame.getGlassPane().setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
        frame.getGlassPane().addMouseListener(mouseAdapter);
        frame.getGlassPane().setVisible(true);
    }
    
    private static void stopWaitCursor(javax.swing.JFrame frame) {
        frame.getGlassPane().setCursor(originalCursor);
        frame.getGlassPane().removeMouseListener(mouseAdapter);
        frame.getGlassPane().setVisible(false);
    }
    
    private static java.awt.Cursor originalCursor = null;
    
    private static final java.awt.event.MouseAdapter mouseAdapter = new java.awt.event.MouseAdapter() {
    };
    
    public static final int DELAY_MS = 250;
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having issues getting Firefox to update a webpage when its class is changed
I have a huge web app that is having issues with memory leak in
I'm having some issues with this layout and having a link that displays on
Given that I'm having issues trying to apply an external log4j configuration via log4j.xml
I'm having issues with my SQL Reporting Services reports. I'm using a custom font
I'm having issues creating an ActionLink using Preview 5. All the docs I can
I'm having issues with color matching css background colors with colors in images on
I am having issues converting a png to tiff. The conversion goes fine, but
At work we're having issues with different people wanting/suggesting different names for a new
I'm having issues passing arguments through run to the windows side To demonstrate, it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.