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 6653277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:14:56+00:00 2026-05-26T01:14:56+00:00

I have a program that is going to do some work (in a background

  • 0

I have a program that is going to do some work (in a background thread) at startup, so I’d like to display a busy cursor for a few moments while a table is being populated. Unfortunately, no matter what I did, I could not get a wait cursor to appear if my window (JFrame) appeared under the pointer. I did some experimentation, and I tracked it down to a simple test case (below). Basically, if there exists a JScrollPanel (e.g. as a parent for a JTable) as a child of the JFrame, then only the default cursor will appear unless I move the pointer out of the window and back in.

Here’s the compilable code:

package cursortest;

import java.awt.Cursor;
import java.awt.Dimension;
import javax.swing.*;

public class CursorTest extends JFrame {

    void initPanel() {
        JScrollPane panel = new JScrollPane();
        panel.setMinimumSize(new Dimension(500, 500));
        panel.setMaximumSize(new Dimension(500, 500));
        panel.setPreferredSize(new Dimension(500, 500));

        GroupLayout layout = new GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addComponent(panel)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addComponent(panel)
        );
    }

    public CursorTest() {
        initPanel();
        setMinimumSize(new Dimension(500, 500));
        setMaximumSize(new Dimension(500, 500));
        setPreferredSize(new Dimension(500, 500));
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        pack();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new CursorTest().setVisible(true);
            }
        });
    }
}

Launch the program so that when the window appears, the mouse pointer is within the bounds of the window. You may have to fiddle with the sizes to get that to happen (that I know I have forced in an artificial way for this example).

If initPanel is NOT called, then the mouse cursor will immediately appear as a wait cursor.

If initPanel IS called, then the mouse cursor will appear as default until you move the pointer out of the window and then back in.

Also, if the JScrollPane is replaced with some other kind of widget, say a JLabel, then this cursor problem does not manifest.

Can anyone help me to figure to how to fix this problem? I’ve thought about also setting the busy cursor for the widgets (my JScrollPanel and/or JTable), but this doesn’t work. You could try it by adding the line panel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));.

Oh, and I should probably mention that I’m doing this on a Mac.

  • 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-26T01:14:57+00:00Added an answer on May 26, 2026 at 1:14 am

    for example

    import java.awt.Cursor;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import javax.swing.*;
    
    public class CursorTest extends JFrame {
    
        private static final long serialVersionUID = 1L;
        private javax.swing.Timer timer = null;
        private JScrollPane scroll;
    
        public CursorTest() {
            scroll = new JScrollPane();
            scroll.setPreferredSize(new Dimension(400,300));
            setTitle("CursorTest");
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setLayout(new FlowLayout());
            add(scroll);
            setLocation(100, 100);
            pack();
            setVisible(true);
            start();
        }
    
        private void start() {
            scroll.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            timer = new javax.swing.Timer(5000, stop());
            timer.start();
        }
    
        public Action stop() {
            return new AbstractAction("Change Cursor Action") {
    
                private static final long serialVersionUID = 1L;
    
                @Override
                public void actionPerformed(ActionEvent e) {
                    timer.stop();
                    scroll.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                }
            };
        }
    
        public static void main(String[] args) {
            java.awt.EventQueue.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    new CursorTest().setVisible(true);
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that is going to take a password as input and
I have a python program that is going to eat a lot of memory,
At work, I have started working on a program that can potentially generate hundreds
I have a program that spawns 3 worker threads that do some number crunching,
Some background: I have an database that I want to use linq-to-sql to update
I have an OpenGL program in which I am doing some augmented reality work.
I have program that has a variable that should never change. However, somehow, it
I have program that runs fast enough. I want to see the number of
I have a program that spits out both standard error and standard out, and
I have a program that creates a Windows user account using the NetUserAdd() API

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.