Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JProgressBar  RSS feed

 
Ali Hassaan
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi every1
i hav a problem with progress bar tht is i hav to progress in a slow motion but its not stopping just reaching 100% very quickly although i use a sleep method....
for(int i=0;i<=100;i+=10){
jProgressBar1.setValue (i);
jProgressBar1.
Thread.sleep (500);
}
pls help me out
 
John Smith
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure, but maybe you need to invoke the sleep method on the current thread, i.e. Thread.currentThread().sleep(500).
 
Ali Hassaan
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Randy Gordon:
I'm not sure, but maybe you need to invoke the sleep method on the current thread, i.e. Thread.currentThread().sleep(500).

Thanx Randy!!
I have use Timer class and its working fine.
Thanx for ur reply
 
john klucas
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ali,
hey can you show me how u r using ur Jprogressbar1.
I will appreciate it!
JL
 
Ali Hassaan
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by john klucas:
Hi ali,
hey can you show me how u r using ur Jprogressbar1.
I will appreciate it!
JL

Timer timer = new Timer(1000, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
progressbar.setValue(current+=10);
}
});
here time is in milliseconds i have start timer on button click event like timer.start();
from tht on progressbar starts working.
 
john klucas
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey thanx a lot. I got that stuff working. But how do i clear the progress bar, i mean when i want to upload another file i want that progress bar to go from 0% to 100% again.
Right now it only works when i do it first time and it shows 100%. How will reset that.
Thanx in advance!
 
Matt Hansen
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To restart it just set the current value of the progress bar to zero and recreate the timer.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!