Java Swing GUI hour glass

12,866

Solution 1

A JProgressBar (possibly in indetermiante mode) sounds right - put that on the tab until the data has been fetched. A well-designed UI shouldn't force the user to wait for long-running tasks to complete and instead allow them to do something else inbetween.

Solution 2

The simplest way is to just call setCursor on the appropriate component (probably the top-level window) with the appropriate Cursor.

component.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

And then set it back when you are done.

component.setCursor(Cursor.getDefaultCursor());

Solution 3

setCursor(int) is deprecated. This is probably a bit cleaner:

setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
Share:
12,866
Frank
Author by

Frank

I've been a Java developer for over 20 years. Recently got a patent for "Interception-resistant Authentication System And Method" : GATE [ Graphic Access Tabular Entry ]. GATE makes user passwords much safer, it helps you to defeat peeking, keylogging, phishing  and dictionary attack. Info : https://gatecybertech.com Demo : https://gatecybertech.net GATE has won multiple cyber security awards. If any organization wants to license it, please contact me.

Updated on June 11, 2022

Comments

  • Frank
    Frank almost 2 years

    There is a JTabbedPane In my Swing program. When user clicks on a tab, the program takes a while to get the data and process the results, then shows the results in the selected tab.

    How can I display a hour glass, or something of that effect so that user knows it's processing data? Not to click on the tab again before it finishes it job.