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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:55:31+00:00 2026-06-01T11:55:31+00:00

I have a simple Swing Java application that performs searches, and the results are

  • 0

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?

  • 1 1 Answer
  • 1 View
  • 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-06-01T11:55:33+00:00Added an answer on June 1, 2026 at 11:55 am

    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 the SwingWorker and concurrency in Swing

    And as always, this site is filled with examples. For example a previous answer of mine uses the SwingWorker class to show progress to a user

    Edit

    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 example progress icon, 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.

    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JTabbedPane;
    import javax.swing.Timer;
    import java.awt.Component;
    import java.awt.EventQueue;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Rectangle;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.geom.AffineTransform;
    
    public class ProgressTabbedPane {
    
      public static void main( String[] args ) {
        EventQueue.invokeLater( new Runnable() {
          @Override
          public void run() {
            JFrame frame = new JFrame( "RotatingIcon" );
            JTabbedPane tabbedPane = new JTabbedPane(  );
            tabbedPane.addTab( "Searching", new RotatingIcon( new ImageIcon( "resources/images/progress-indeterminate.png" ), tabbedPane ),
                               new JLabel( new ImageIcon( "resources/images/rotatingIcon.gif" ) ) );
            frame.getContentPane().add( tabbedPane );
            frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
            frame.pack();
            frame.setVisible( true );
          }
        } );
      }
    
      private static class RotatingIcon implements Icon{
        private final Icon delegateIcon;
        private double angleInDegrees = 90;
        private final Timer rotatingTimer;
        private RotatingIcon( Icon icon, final JComponent component ) {
          delegateIcon = icon;
          rotatingTimer = new Timer( 100, new ActionListener() {
            @Override
            public void actionPerformed( ActionEvent e ) {
              angleInDegrees = angleInDegrees + 10;
              if ( angleInDegrees == 360 ){
                angleInDegrees = 0;
              }
              component.repaint();
            }
          } );
          rotatingTimer.setRepeats( false );
          rotatingTimer.start();
        }
    
        @Override
        public void paintIcon( Component c, Graphics g, int x, int y ) {
          rotatingTimer.stop();
          Graphics2D g2 = (Graphics2D )g.create();
          int cWidth = delegateIcon.getIconWidth() / 2;
          int cHeight = delegateIcon.getIconHeight() / 2;
          Rectangle r = new Rectangle(x, y, delegateIcon.getIconWidth(), delegateIcon.getIconHeight());
          g2.setClip(r);
          AffineTransform original = g2.getTransform();
          AffineTransform at = new AffineTransform();
          at.concatenate(original);
          at.rotate(Math.toRadians( angleInDegrees ), x + cWidth, y + cHeight);
          g2.setTransform(at);
          delegateIcon.paintIcon(c, g2, x, y);
          g2.setTransform(original);
          rotatingTimer.start();
        }
    
        @Override
        public int getIconWidth() {
          return delegateIcon.getIconWidth();
        }
    
        @Override
        public int getIconHeight() {
          return delegateIcon.getIconHeight();
        }
      } 
    }
    

    A screenshot for reference. A shame the icons do not rotate in the screenshot.
    SSCCE screenshot

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a swing Java application that preserves a lot of data (you can
I have a Java Swing application, that has many JTextFields and a datamodel. When
I'm making a simple Kakuro application in Java Swing and I have used JButton
I have simple WinForms application where modifying Windows Registry. The problem is that in
I have developed a Java Swing application, which uses the SwingWorker class to perform
Using Netbeans 6.8 and metro 2.0 I have written a simple application that makes
I made a simple Swing application. But the rendering behaves buggy. Have I done
Hi I have created a sample java swing application Mac os. Now I want
I have a simple console application that runs calculations in several threads (10-20 of
I've been tasked with doing refactoring to a Java Swing application we have here

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.