Java Swing GUI hour glass

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Java Swing GUI hour glass



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.


JTabbedPane



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.




5 Answers
5



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.





To that end, I would hope that the long-running task is done in a separate thread.
– Powerlord
Dec 21 '09 at 16:24





I'll try this, makes sense, so user will know how long to wait.
– Frank
Dec 21 '09 at 17:11



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());





Great, it's simple and effective.
– Frank
Dec 21 '09 at 17:10





This helped a lot. Thank you.
– Radu Murzea
May 9 '13 at 19:20



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


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



As the other answers mention, you can set a wait cursor, but you also mention preventing additional mouse clicks. You can use a glass pane to prevent clicks on components until the long operation is finished. In addition to the Sun tutorials on the glass pane, there is a nice example at http://www.java2s.com/Code/Java/Swing-JFC/DemonstrateuseofGlassPane.htm



I would as other mentioned






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard