I am trying a simple socket based file transfer program to include a ProgressMonitorInputStream, my file transfer is working fine. But the progressMonitor never shows up.
I am sending a file from server to client, when it connects, my file is getting transfered perfectly, but just don’t understand why the ProgressMonitor doesn’t come up.
I searched some examples, they used ‘this’ instead of ‘new Jframe()’ in PMIS, but since I was inside main(), it didn’t allow me to do that.
//client
InputStream is = sock.getInputStream();
BufferedInputStream bis = new BufferedInputStream(
new ProgressMonitorInputStream(new JFrame(),"reading",is));
while ((read = bis.read(buffer,0,buffer.length)) != -1) {
//read from socket...now write to file
}
You have re_read tutorial about How to Use Progress Bars, there is basic description for ProgressMonitorInputStream
Swing is single threaded and if you want to move with
progress, then you have to redirect thisStreamto theBackroundTask, tutorial aboutJProgressBarimplelemnts SwingWorker, another options is wrap that to theRunnable#Thread, but in this case output to the GUI must be wrapped intoinvokeLater()