• Post Reply Bookmark Topic Watch Topic
  • New Topic

JDialog is blank whilst other tasks are running

 
Fabricio Sanchez
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi There,
I have an instance of JDialog with some information that I would like to update as I run a series of methods. All I am updating are JLabel instances by using the setIcon() method (and in future setText() too).
The JDialog only updates after all my methods have run, even though I use the setIcon() method in between my update method calls. The JDialog remains blank until all the methods have finished.
I have the following code:

Is there anyway I can force my JDialog instance to refresh all the way through and not just after all my methods have run?
Thank you for your help in advance,
Fabricio.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your problem has to do with the Event thread in Swing. Swing is not multithreaded by nature. So painting events and other events happen in the same thread. And painting is always the last event to occur.
What you need to look at is the SwingUtilities.invokeLater() method so that you can force your tasks to run in a seperate thread from the event thread and that way your painting will take place as you want.
 
Fabricio Sanchez
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx Gregg,
I turned out that Threads solved the problem after all!
All I did was to create a Thread to do all the working and updating, whilst leaving the JDialog instance itself in the main Thread, and presto! No more blank JDialog display problems.
This is a snippet for anyone who might be interested (Comments appreciated, if this is utter rubish...)

[ May 06, 2004: Message edited by: Fabricio Sanchez ]
 
Paper has not yet been outlawed – so let your Java Swing application print with wild abandon: JPDF
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!