I have a simple Swing Java application that performs searches, and the results are shown in a new tab. While the search is running, I want to show a progress icon or animation in the title of the tab. I tried adding a gif icon, but it doesn’t animate. Is there a reason why this isn’t working?
I have a simple Swing Java application that performs searches, and the results are
Share
The Swing tutorial about progress bars (and showing progress in general) is a very good place to start. It shows you how to perform long-lasting operations on a worker thread by using a
SwingWorker, and updating your UI at certain intervals to show progress of the long-lasting operation to the user. There is another tutorial available for more information on theSwingWorkerand concurrency in SwingAnd as always, this site is filled with examples. For example a previous answer of mine uses the
SwingWorkerclass to show progress to a userEdit
As I missed the title of tab part of your question. You could create a ‘progress icon’ and set that on the tab. The
SwingWorkercan then be used to update the icon.An example of such an icon is
, which is basically an image you rotate each time some progress is made. The tabbed pane tutorial shows you how to add icons to your tabs (or even use custom components)
Edit2
As it seems my Mac in combination with JDK1.7 makes it much easier to show an animated gif then on other systems, I created a small SSCCE as well, quite similar to that of Andrew but with a rotating icon which does not look like it has been created by, and I quote, ‘demented Chimpanzee’. The rotating icon code comes from this site (I used a stripped down version and added the timer). Only thing I am not too happy about is the fact I need to pass my tabbed pane to the rotating icon to trigger. Possible solution is to pull the timer outside the
RotatingIconclass, but hey, it’s only an SSCCE . Images are not included but were found with Google.A screenshot for reference. A shame the icons do not rotate in the screenshot.
