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 6864949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:58:43+00:00 2026-05-27T02:58:43+00:00

I currrently have a SwingWorker that sends a HTTP Request and I override the

  • 0

I currrently have a SwingWorker that sends a HTTP Request and I override the SwingWorker’s done() method to change contents in a JFrame. I want to basically remove everything and add a new members panel on the JFrame depending on the values returned from the Server.

Now, the problem I am facing is that when I invoke the following methods below on the JFrame, it doesn’t remove anything from the JFrame nor does it change it’s contents contained within the Frame.

//TODO: Investigate why JFrame content pane won't repaint.
f.removeAll();
//Pass the frame f reference only into MainDisplay, it doesn't actually do anything apart from allowing a class to add a JMenuBar on the JFrame.
f.add(new MainDisplay(f)); 
f.getContentPane().invalidate();
f.getContentPane().validate();
f.getContentPane().repaint();

The current fix I have is this below but I would rather change the contents of the JFrame rather then loading a new one up.

f.dispose();
f=new ApplicationFrame();

I’ve looked through previous answers on here and on Google and some state use validate() or invalidate() whilst calling repaint() to repaint the JFrame.

Any suggestions/help would be much appreciated.

Edit: I think I am going to debug more since there must be something else going wrong.

  • 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-27T02:58:44+00:00Added an answer on May 27, 2026 at 2:58 am

    for example

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class MyFrame extends JFrame {
    
        private static final long serialVersionUID = 1L;
    
        public MyFrame() {
            final JPanel parentPanel = new JPanel();
            parentPanel.setLayout(new BorderLayout(10, 10));
    
            final JPanel childPanel1 = new JPanel();
            childPanel1.setBackground(Color.red);
            childPanel1.setPreferredSize(new Dimension(300, 40));
    
            final JPanel childPanel2 = new JPanel();
            childPanel2.setBackground(Color.blue);
            childPanel2.setPreferredSize(new Dimension(800, 600));
    
            JButton myButton = new JButton("Add Component ");
            myButton.addActionListener(new ActionListener() {
    
                public void actionPerformed(ActionEvent e) {
                    parentPanel.remove(childPanel1);
                    parentPanel.add(childPanel2, BorderLayout.CENTER);
                    parentPanel.revalidate();
                    parentPanel.repaint();
                    pack();
                }
            });
            setTitle("My Empty Frame");
            setLocation(10, 200);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            parentPanel.add(childPanel1, BorderLayout.CENTER);
            parentPanel.add(myButton, BorderLayout.SOUTH);
            add(parentPanel);
            pack();
            setVisible(true);
        }
    
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    MyFrame myFrame = new MyFrame();
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a string, say $line='55.25040882, 3,,,,,,' , that I want to remove
I currrently have some code that converts a .doc document to html but the
We currently have an application that sends out SMS to users, it acts like
I currently have one class with 4 methods. I need to change that to
Currently have a drop down menu that is activated on a hover (from display:none
I currently have a XSLT 2.0 Stylesheet that I am trying to remove empty
I currently have one project that currently contains multiple packages. These packages make up
I currently have a deployed app (fortworth.herokuapp.com) that I am attempting to sort movies
I am currrently using BeautifulSoup to scrape some websites, however I have a problem
I currently have a Web Application that runs off a global Javascript-based API, and

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.