How create progress bar while file transferring

大兔子大兔子 提交于 2019-11-28 02:26:57

I can think of two ways.

Swing Worker

Start by wrapping you copy code into a SwingWorker, using the setProgress method to update the progress and a property change listener to monitor changes to the progress property.

When the progress property changes, you would then update the UI.

This solution will require you to supply you own UI

Progress Monitor

Use a ProgressMonitorInputStream, which comes with it's own UI.

InputStream in = new BufferedInputStream(
    new ProgressMonitorInputStream(
        parentComponent,
        "Reading " + fileName,
        new FileInputStream(fileName)));

(Example stolen from Java Docs)

Here you can find same example. Making Progress With Swing's Progress Monitoring API.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!