JProgressBar bar not showing up till complete

6

6e

Hi thanks for reading.

Im sure the answer to this is simple, it just eludes me at this point.

Im tring to use a progress bar to simply show the progress of 55 files
being created and saved to disk. However when I use the JProgressBar
in my code, it only shows up when the task is completed... Obviously I
need it to be shown updating the entire time, seems like im missing
something pretty basic.

heres the code for your perusal, the updates occurs later in the code,
but since its not showing up until it is completed I believe the error
is here + Thanks! :

//start up progress FRAME
JFrame jfrProgress = new JFrame("Creating Movie...");
Container contentPane = jfrProgress.getContentPane();
SpringLayout layout = new SpringLayout();
contentPane.setLayout(layout);

//set up progress BAR
JProgressBar pbProgress;
pbProgress = new JProgressBar(ISTARTFRAME, iFinalFrame);
pbProgress.setValue(ISTARTFRAME);
pbProgress.setStringPainted(true);
pbProgress.setString("Step 1 - Creating Files...");
pbProgress.setSize(500, 40);

//add progress bar to frame
jfrProgress.getContentPane().add(pbProgress);

//display frame
jfrProgress.setLocation(400, 300);
jfrProgress.setSize(250, 100);
pbProgress.setVisible(true);
jfrProgress.setVisible(true);
 
A

Andrew Thompson

Im sure the answer to this is simple, it just eludes me at this point.

Im tring to use a progress bar to simply show the progress of 55 files
being created and saved to disk. However when I use the JProgressBar
in my code, it only shows up when the task is completed... Obviously I
need it to be shown updating the entire time, seems like im missing
something pretty basic.

Now thoroughly out of date, but this qn. was covered in
an early version..
<http://www.physci.org/guifaq.jsp#2.1>

Note that GUI questions are best directed to..
<http://www.physci.org/codes/javafaq.jsp#cljg>

HTH
 
T

Thomas Fritsch

6e said:
Hi thanks for reading.

Im sure the answer to this is simple, it just eludes me at this point.

Im tring to use a progress bar to simply show the progress of 55 files
being created and saved to disk. However when I use the JProgressBar
in my code, it only shows up when the task is completed... Obviously I
need it to be shown updating the entire time, seems like im missing
something pretty basic.

heres the code for your perusal, the updates occurs later in the code,
but since its not showing up until it is completed I believe the error
is here + Thanks! :
Since you didn't bother posting a complete compilable example, this is
how I completed it (based on my vague guesses) to get it compiled and
running:

import java.awt.*;
import javax.swing.*;

public class Main
{
static int ISTARTFRAME = 0;

public static void main(String[] args)
{
int iFinalFrame = 100;
//start up progress FRAME
JFrame jfrProgress = new JFrame("Creating Movie...");
Container contentPane = jfrProgress.getContentPane();
SpringLayout layout = new SpringLayout();
contentPane.setLayout(layout);

//set up progress BAR
JProgressBar pbProgress;
pbProgress = new JProgressBar(ISTARTFRAME, iFinalFrame);
pbProgress.setValue(ISTARTFRAME);
pbProgress.setStringPainted(true);
pbProgress.setString("Step 1 - Creating Files...");
pbProgress.setSize(500, 40);

//add progress bar to frame
jfrProgress.getContentPane().add(pbProgress);

//display frame
jfrProgress.setLocation(400, 300);
jfrProgress.setSize(250, 100);
pbProgress.setVisible(true);
jfrProgress.setVisible(true);
}
}

For me the progressbar shows up, and it visualizes 0% as expected,
because the progress bar is never updated by further
pbProgress.setValue(...) calls.

I'm sure you would get much more enlightening answers from this group,
if you post a SSCCE <http://www.physci.org/codes/sscce.jsp> here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top