Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 897447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:53:22+00:00 2026-05-15T14:53:22+00:00

i have a program that takes some time creating pdf files i would like

  • 0

i have a program that takes some time creating pdf files
i would like to show progress to user

when i finish making a pdf file i try to call the progressbar to update its status:

ProgressDialog progress = new ProgressDialog(instance, numberOfInvoices);
progress.setVisible(true);
progress.setAlwaysOnTop(true);

for(int i = 0 ; i<numOfPdfs ; i++){
    progress.change(i + 1);
}

the progressdialog looks like this:

public class ProgressDialog extends JDialog {

    private JProgressBar progressBar;

    public ProgressDialog(Window parent, int aantal) {
        super(parent);

        this.setPreferredSize(new Dimension(300, 150));

        progressBar = new JProgressBar(0, aantal);
        progressBar.setValue(0);
        progressBar.setSize(new Dimension(280, 130));
        this.add(progressBar, BorderLayout.CENTER);

        this.pack();
        this.setLocationRelativeTo(parent);
    }

    public void change(int aantal) {
        if (aantal < progressBar.getMaximum() && aantal >= 0) {
            progressBar.setValue(aantal);
        }
    }
}

all i get is an empty window (white)

i looked around on this forum but the treads solution seems soo complex

between calculation of 2 pdf files i should be able to update the gui, right?

ok colin

i tried this: (complete class)

public class ProgressDialog extends JDialog {

    private JProgressBar progressBar;
    private String message;
    private static int number;

    public ProgressDialog(Window parent, int max, String message) {
    super(parent);

    this.message = message;
    this.setPreferredSize(new Dimension(300, 150));

    progressBar = new JProgressBar(0, max);
    progressBar.setValue(0);
    progressBar.setSize(new Dimension(280, 130));
    progressBar.setString(message + " 0/" + progressBar.getMaximum());
    progressBar.setStringPainted(true);
    this.add(progressBar, BorderLayout.CENTER);

    this.pack();
    this.setLocationRelativeTo(parent);

    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));


    }

    public void change(int number) {
    ProgressDialog.number = number;
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
        int number = ProgressDialog.getAantal();
        if (number < progressBar.getMaximum() && number >= 0) {
            progressBar.getModel().setValue(number);
            progressBar.setString(message + " " + progressBar.getValue() + "/" + progressBar.getMaximum());
            System.out.println("progressbar update: " + number + "/" + progressBar.getMaximum());
        } else {
            setCursor(null);
            System.out.println("progressbar terminated");
        }
        }
    });
    }

    public static int getAantal(){
    return number;
    }
}

now it still shows the empty window
but when all pdf’s are ready it does show the progressbar with 0% completed
then it closes (like it should do)

any idea why it stays blank during process?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:53:22+00:00Added an answer on May 15, 2026 at 2:53 pm

    You do need to do it with threads. Better learn it than escape, because it’s a common GUI framework design.

    It can be as simple as:

    public void change(int aantal) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                if (aantal < progressBar.getMaximum() && aantal >= 0) {
                    progressBar.setValue(aantal);
                }
            }
        });
    }
    

    Or replace invokeLater() with invokeAndWait().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program, that takes a long time to load. Because of this,
I have a completely non-interactive python program that takes some command-line options and input
I have a library consisting of some 300 c++ files. The program that consumes
I have a database-synchronisation task that takes some time to process, as there are
I have a python program that takes the md5 & sha1 hash values of
I have a perl program that takes input and output file arguments, and I'd
I have been assigned wit the task to write a program that takes a
I have a Python program that sends keystrokes to another application using SendKeys. Some
Is there any program that will scan two code files, compare, and show you
I have a simple WebView application which takes some time to load up when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.