Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JProgressBar

Status
Not open for further replies.

ronnyjljr

IS-IT--Management
Nov 23, 2003
249
US
Hello,


I have a JProgress bar and I want to set increase it's value as it goes through a while loop.

Something like this...

Code:
[blue]
entry = getNextBlahEntry();
   while(entry!=null)
   {  
      CurrentCount++;
      myProgressBar.setValue(CurrentCount);
     [green]//Do some other stuff [/green]
   }
[/blue]


All events are delayed until the while loop completes. How do I force the progress bar to update?

Thanks,
Ron

typedef map<GiantX,gold, less<std::shortestpathtogold> > AwesomeMap;
 
Hi Guys,

I figured this one out and I am posting the answer just in case someone ever stumbles upon this.

Inside the while or for loop you need to call...
Code:
[blue]
		myFrame.update(myFrame.getGraphics());
[green]//Where myFrame is the JFrame which contains the components[/green]

[/blue]

Cheers!
~Ron

typedef map<GiantX,gold, less<std::shortestpathtogold> > AwesomeMap;
 
If you're using a progress bar then it figures that you're doing something which could take a while. If this process isn't to do with the GUI then it should be run in its own thread. The update in the JProgressBar's percentage state should be done using a call to SwingUtilities.invokeLater.

The basic idea is that all long-running 'business' processes be run in a separate thread from the Swing/AWT Dispatch thread, whilst any GUI updates generated in this separate thread be achieved via a call to javax.swing.SwingUtilities.invokeLater(Runnable).

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top