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?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
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 theSwingWorker
and concurrency in SwingAnd as always, this site is filled with examples. For example a previous answer of mine uses the
SwingWorker
class 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
SwingWorker
can 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
RotatingIcon
class, 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.
@Andrew Thompson
I don't want to read whole ...., but put together code by yours and @trashgod's majesty
1) use
Htlm
(I'm not good in plain Html)2) use
GlassPane
withJLabel#(setOpaque(true))
3) use
JLayer
(JXLayer
is better, becasue Sn'Oracle remove important methods == my view)4) you have to force ..... for Swing JComponents by @aterai
5) Rob's Animated Icon a few times metioned support by Rob for
JTabbedPane
code