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

  • Home
  • SEARCH
  • 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 8526239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:12:58+00:00 2026-06-11T08:12:58+00:00

I have a JFrame with a CardLayout component. I am using the CardLayout to

  • 0

I have a JFrame with a CardLayout component. I am using the CardLayout to switch between different JPanel’s at different moments of the application execution. At some point I am using a SwingWorker Object to generate some XML files. In this time I want to display another JPanel in my window to tell the user to wait. On this JPanel I want to switch between 3 labels.

  • JLabel 1 would be : “Please wait.”
  • JLabel 2 would be : “Please wait..”
  • JLabel 3 would be : “Please wait…”

Right now the code looks like this:

        ConvertersWorker.execute();
        CLayout.show(Cards, WAIT_PANEL);


        Timer t =new Timer(500, new ActionListener()
        {
            @Override
            public void actionPerformed(ActionEvent e) {
                WaitPanel.SwitchLabels();
            }               
        });
        t.start();

        while (!this.finishedConverting)
        {

        }
        //After this im am executing other methods based on the generated XML files

The SwingWorker code:

SwingWorker<Boolean, Void> ConvertersWorker = new SwingWorker<Boolean, Void>() {
    public Boolean doInBackground() {
        Boolean result = RunConverters();
        return result;
    }
    public void done() {
        try {
            finishedConverting = get();
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        } catch (ExecutionException ex) {
            ex.printStackTrace();
        }
    }
 } ;

The second JPanel is not even displayed because the JFrame blocks. It blocks because of the while loop but I don’t know how to implement it differently. And also the method done() from the SwingWorker is never executed. If it were executed then the finishedConverting variable would have been set to true and the while loop would have stopped. Can anyone help me to find a better solution?

  • 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-06-11T08:12:59+00:00Added an answer on June 11, 2026 at 8:12 am

    I know you solved this but that’s happening because you are using just one thread, and it blocked because of the While, so you need to create a new thread to handle this

    new Thread(){  
      public void run() { 
        //code here
      }
    }.start();
    

    and to refresh the content of a JPanel you can use

    myJpanel.doLayout();
    

    or

    myJpanel.repaint();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 JPanels and 1 JFrame, and I'm trying to switch between panels
I have a JFrame inside of which is a jpanel that im using as
I've started working on a Java desktop application using netbeans. I have 7 different
I have a JFrame with some a JTextField and a JButton. I want it
I have a JFrame with JScrollPane in it. I have JPanel inside a scrollPane.
I have a JFrame(frm) in which I've added a JPanel (pnl1)..which in turn has
I have JPanel has already added to JFrame. And I have dynamically added JPanel.
I have a JFrame with an associated JPanel which fill the screen, both having
I have a JFrame and some JButtons , JLabels and a JTextfield . I
I have a JFrame with a JPanel on it ( JPanel is private in

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.