Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / May 2005

Tip: Looking for answers? Try searching our database.

JProgressBar Flickering!

Thread view: 
Ad - 22 May 2005 04:09 GMT
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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.