How create progress bar while file transferring

前端 未结 2 789
青春惊慌失措
青春惊慌失措 2020-12-07 06:38
import java.awt.Component;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.I         


        
相关标签:
2条回答
  • 2020-12-07 07:01

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

    0 讨论(0)
  • 2020-12-07 07:06

    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)

    0 讨论(0)
提交回复
热议问题