Reputation: 704
I am trying to show a loading gif inside jlabel while some web request is done. I have done some research and I discovered that I need to use Event dispatch thread in order to do that. But it seems it is putting this task in a queue to execute later. I would like to execute in parallel, that means, while the request is done, a gif is showing on screen to inform client that some task is being done.
But this gif only appears after the request is completed.
I have used invokeLater and Swing timer without success. Maybe there is something wrong with my code.
I have this code executed:
label.setVisible(true);
label.getParent().revalidate();
label.getParent().repaint();
Inside the runnable piece of code.
Am I doing something wrong? Could you please help me?
Upvotes: 0
Views: 780
Reputation: 343
You need to use SwingWorker
thread. All swing related things like window paintings and events will execute on EDT. And you will perform background tasks like requesting and retrieving web page in background thread (SwingWorker
).
API: https://docs.oracle.com/javase/7/docs/api/javax/swing/SwingWorker.html
Information: http://en.wikipedia.org/wiki/SwingWorker
Upvotes: 1