Updating the progress bar from a workflow

I am creating a java program that downloads N elements from the server. I would like to have a work schedule that shows "already loaded items" / N percent. Right now I am updating the progressbar value by passing the link to the GUI object to the stream, but it makes the code ugly (the GUI class creates a stream containing a link to the GUI itself, creating a kind of loop). Is there a better way to do this?

+3
source share
4 answers

SwingWorkerhas some advantages in this context, as suggested in this example .

+5
source

API JProgressBar Swing , Progress Bars .

+2

"". , GUI, .

+2

, , - . . GUI ( - , ).

, , ( ).

, ProgressTracker ( : ). JProgressBar, JLabel, ... ProgressTracker , .

SwingWorker has some code that helps merge several updates, but it is built on the assumption that long-running tasks should inherit from SwingWorker, which does not help separate problems. It really depends on you in which direction - I personally prefer that operations with my data have nothing to do with the graphical interface.

Remember to post your updates for any Swing components on EDT using SwingUtilities.invokeLater ()

0
source

Source: https://habr.com/ru/post/1787200/


All Articles