|
-
Nov 8th, 2007, 02:11 PM
#1
Thread Starter
Hyperactive Member
jProgressBar - How???
This is my 4th attempt at trying to figure out how to use a progressbar, this is what I have but its not working:
Code:
class Counter extends Thread implements Runnable{
/* This class simply runs a thread to count to 50 */
public int count = 1;
public void run() {
while (count < 50) {
try {
sleep(1000);
Thread updateThread = new Thread(this, "Count Program");
//updateThread.setPriority(NUMCOUNTERS+2);
jProgressBar1.setValue(count);
} catch (InterruptedException e) { }
count++;
}
stop();
}
}
}
How can I simply make the progressbar move 1 second at a time.
Help would be greatly appreciated
-
Nov 9th, 2007, 03:34 AM
#2
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
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Nov 13th, 2007, 02:14 PM
#3
Thread Starter
Hyperactive Member
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?
-
Nov 13th, 2007, 02:29 PM
#4
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
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Nov 13th, 2007, 02:46 PM
#5
Thread Starter
Hyperactive Member
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
-
Nov 13th, 2007, 02:56 PM
#6
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
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Nov 13th, 2007, 03:03 PM
#7
Thread Starter
Hyperactive Member
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
-
Nov 13th, 2007, 03:11 PM
#8
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
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Nov 13th, 2007, 04:18 PM
#9
Thread Starter
Hyperactive Member
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%
-
Nov 13th, 2007, 04:49 PM
#10
Re: jProgressBar - How???
because the count is iterating through 1-7 out of 100%
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Nov 13th, 2007, 06:27 PM
#11
Thread Starter
Hyperactive Member
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
-
Nov 14th, 2007, 01:04 AM
#12
Re: jProgressBar - How???
you're passing 50 milliseconds to the Thread.sleep method, and I still think it's a MAC compatibility issue
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|