Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Updation of ProgressBar??

 
Bikash Paul
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all friends,
Iam facing problem with updation of progressBar of my swing Interface.I want to update my progressBar by the bytes which is already written by server on destination.It is basically a uploading software.For that iam using a thread and i have written a method of taking the bytes from servlet.And in servlet iam writting bytes by 'PrintWriter' in loop.But I couldn't update progressBar.Can any one plz guide me where i am wrong in my code.If possible plz give me some code for that.Iam pasting those portion of codes only.Eagerly waiting for someone reply.

Regards
Bikash
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is that swing components are not thread safe. You should never change the state of a swing component except in the swing dispatcher thread. You can use a javax.swing.Timer to do it like this:

Moving this to the Swing forum.
 
Viswa Laksh
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this code snippet would help you. Try this..
Code for downloading and updating progress bar. "FileRecv" is the calling program and progress bar is declared as static.

Calling code from "FileRecv" Program.

~Viswa
 
Mallick Choppa
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I think its not related to swing or any thing else. See when u are receiving by using "BufferInputStream" actually all the data gets buffered until it is full only then it is read out of the buffer. So you just need to add
"out.flush();" on ther server code as below.
os.write(buf, 0, cc);
tot += cc;
out.println(tot);
out.flush(); //this u need to this.
if (str.equals(str1)) break;
Hope this works, if you want any thing about this u can mail to my id below.
Mallick
mallick@orillion.stph.net
 
Bikash Paul
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all friends,
I have tried as per Michael Morris and Mallick Choppa suggestion I have add Updater class in my swing interface code and also add out.flush(); in my servlet code.But I couldn't slove my problem.Now my server stop writting file after wrtting some portion of file on remote destination and no progressBar activity.And my swing interface going to hang.Iam explaining once again i want to update my progressBar when server writting file on destination.I can show the progress of reading file by my swing interface but i want to show the progress of writting of file.Now Iam pasting code of my method through Iam uploading file:-

My checkForFilesToUpload method check my hot folder every after 30 second for files and take the file in listFiles() in array of file and by sorting files by size it strats uploading of smallest file using my doPost method one by one from queue thats why i have called my doPost method inside checkForFilesToUpload method.Can any plz guide me where iam wrong in my swing interface or in servlet.
Regards
Bikash
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic