How to add a progress bar?

前端 未结 4 1805
误落风尘
误落风尘 2020-12-15 12:22

I have been trying to understand how to add a progress bar, I can create one within the GUI I am implementing and get it to appear but even after checking through http://doc

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-15 13:15

    See my answer on another SO question which includes an example of a JProgressBar which gets updated by using a SwingWorker. The SwingWorker is used to execute a long running task in the background (in case of the example it is just a regular Thread.sleep) and report on progress at certain intervals.

    I would also strongly suggest to take a look at the Swing concurrency tutorial for more background info on why you should use a SwingWorker when performing long-running tasks which interfere with the UI.

    A similar example as the one I posted is available in the Swing tutorial about JProgressBars, which it also worth looking at

提交回复
热议问题