How to use the progress bar in Java (Netbeans GUI)

I am not too experienced with Java and it is difficult for me to get a progress bar. I use the built-in graphical user Netbeans. Currently, my program is reading images from a directory into an image array. Obviously, this takes a little time, so I would like a simple progress indicator to update the user to see how busy he is. I used one of those drag and drop components.

-I currently you can get the number of files in a directory and calculate the percentage of downloaded files. Files are successfully loaded into the array, but the progress bar is only updated after all files have been downloaded. I tried reinstalling and repainting while I loop, but it doesnโ€™t work -I tried various docs.oracle tutorials, but it seemed like nothing could get it working. -I believe SwingWorker is a class that I should use, is this correct?

Any help with an example or some tips would be greatly appreciated! Thank!

+5
source share
1 answer

Yes, you are faced with the trap of all new Swing programmers - Dispatching Thread event

, Thread Swing. Is , repaint .

- , EDT, .

SwingWorker Concurrency Swing, , , , , SwingWorker, JTextArea

+2

All Articles