Hi everyone! I just have a little question here!
I have a Swing GUI in which I put a JProgressBar.
I also have a static class where I put a static variable JProgressBar.
In my main program, because the static methods are time consuming, I
start a new thread, where I initialize the static JProgressBar with the
one in main gui.
So I'm able to update the text, value, etc in the GUI without locking
my main program.
The problem is:
I put progression report [ progressBar.setValue(int) ] in my loops to
see the change. It works perfectly BUT!!!
Every time it sets a new value, the progress bar show a lot of
flickering! I enabled double buffering on it, but no effect!
How can I remove this bad effect??? If some knows please tell me quick
:)
Thanks,
Ad
Tjerk Wolterink - 22 May 2005 22:50 GMT
> Hi everyone! I just have a little question here!
>
[quoted text clipped - 21 lines]
> Thanks,
> Ad
You should update the progressbar in the event-dispatching thread.
See http://java.sun.com/docs/books/tutorial/uiswing/components/progress.html
for more info.
Thomas Weidenfeller - 23 May 2005 08:17 GMT
> Hi everyone! I just have a little question here!
[...]
> I put progression report [ progressBar.setValue(int) ] in my loops to
> see the change. It works perfectly BUT!!!
>
> Every time it sets a new value, the progress bar show a lot of
> flickering! I enabled double buffering on it, but no effect!
Please use less exclamation marks and show us more code.

Signature
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
Ad - 23 May 2005 11:27 GMT
Ok Thomas, so here it comes
I have MyGUI.java :
-------------------
public class MyGUI extends JFrame {
StatusBar statusBar; -> My own status bar, which contains a JProgressBar
Thread runThread;
public MyGUI() {
statusBar = new StatusBar();
...
stats = new Thread() {
public void run() {
MathOper.progress = statusBar.getProgressBar();
System.out.println("--- Create matrix ---");
double [][] matrix = MathOper.setParam(values);
}
};
stats.setPriority(Thread.MIN_PRIORITY);
stats.start();
...
}
...
}
and in MathOper.java :
----------------------
public class MathOper {
public static JProgressBar progress;
public static double [][] setParam(int [][] test) {
// test is a square matrix
int width = test.lenghth;
int height = test[0].length;
double [][] retValue = new double[width][height]
progress.setString("setParam method...");
progress.setValue(0);
progress.setMaximum(width * height);
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
retValue[i][j] = ... -> too long to put here
progress.setValue((i+1)*(j+1));
}
}
return retValue;
}
}
As I pass the progressBar from MyGUI.java -> MathOper.java by
reference, from what I know it's like a pointer to the same space in
memory, so both can update the values, that was what I needed.
I put an animation made with Wink here to see what I mean, on my
computer it's even faster that that:
http://ece.fsa.ucl.ac.be/asimion/problem.htm
Still don't figure out what's the matter.
Thanks,
Ad
Thomas Weidenfeller - 23 May 2005 12:22 GMT
> Ok Thomas, so here it comes
See Q2.4, Q3.2, and Q4.2 of the FAQ.
/Thomas

Signature
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq