Re: jProgressBar - How???
Code:
public void start(){
Thread thread = new Thread(new Runnable() {
private int count;
public void run() {
while (count < 50) {
try {
Thread.sleep(1000);
//updateThread.setPriority(NUMCOUNTERS+2);
jProgressBar1.setValue(count);
} catch (InterruptedException e) {
}
count++;
}
}
}, "Count Program");
thread.start();
}
I think you've forgotten to call the "thread.start()" method
Re: jProgressBar - How???
So here is what I did:
I put your void function within my class. As soon as the jButton is clicked I call start() and then a loop goes through a file and creates a model. The app still freezes while its looping through the file and I dont see the progressbar filling up. What do you think is wrong?
Re: jProgressBar - How???
Are you sure the "JButton" click event is handled?
try a JOptionPane message to make sure its working
Otherwise I have no idea what to do, because this should work for java 1.4
Re: jProgressBar - How???
hmmmmm, seems like the thread is working properly, because when I choose a huge file and the loop is done, I see the progressbare like 10% full. But the problem is I dont see it filling up during the loop, I see it go from 0% to 10%. Do I need to put in a form refresh? or a progressbar refresh? Im using netbeans, FYI
and yes the joptionpane message worked
Re: jProgressBar - How???
Doesn't matter what IDE you're using.
What is you're OS?
And are you sure your the loop is iterating 100 times?
if not. Set the max of the progressbar to the appropriate value
Re: jProgressBar - How???
Im using mac OS X 10.4.10.
Im using that same exact code as above, as of now the progressbar and the loop dont share any values. I just want to get the simple case working before I make it more complicated. Simply have the progressbar move up 1 second at a time while the loop is processing.
Will it help if I post the entire class here? Its not very big
Re: jProgressBar - How???
Not really
If you're using MAC OS you'll have to make sure what version of Java you should be using. Because java have some compatibility issues with MAC
Re: jProgressBar - How???
Forget about all that for a sec, check this out:
Code:
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
int count=0;
while (count < 7) {
try {
Thread.sleep(1000);
//updateThread.setPriority(NUMCOUNTERS+2);
jProgressBar1.setValue(count);
jProgressBar1.updateUI();
} catch (InterruptedException e) {
}
count++;
}
}
Try that, how come I dont see the progressbar raising? All I see is it goes from 0% to 7%
Re: jProgressBar - How???
because the count is iterating through 1-7 out of 100%
Re: jProgressBar - How???
let me try again:
Code:
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
//String ans;
// ans = JOptionPane.showInputDialog(null, "Speed in miles per hour?");
int count=0;
while (count < 100) {
try {
Thread.sleep(50);
//updateThread.setPriority(NUMCOUNTERS+2);
jProgressBar1.setValue(count);
jProgressBar1.updateUI();
} catch (InterruptedException e) {
}
count++;
}
}
how come I dont see the progressbar raising as it goes through the loop? All I see is it goes from 0% to 100% when the loop is finished
Re: jProgressBar - How???
you're passing 50 milliseconds to the Thread.sleep method, and I still think it's a MAC compatibility issue