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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:33:24+00:00 2026-05-21T04:33:24+00:00

I have a top level container (JFrame) that contains two JPanels. One of the

  • 0

I have a top level container (JFrame) that contains two JPanels. One of the JPanel children has a property that will change and that needs to trigger an update on one of the other JPanel components (a JProgressBar).

How can I access this component from the JPanel where the property change is triggered? If this is not the correct way to do it, is there any other method to propagate the property change to it?

  • 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-21T04:33:25+00:00Added an answer on May 21, 2026 at 4:33 am

    Sounds like you need to use an Observer of some sort. Here is a simple example of having the JFrame become aware of property changes in the panel and then updating the other panel accordingly. If your design gets complex and you have many different components that must become aware of changes in each other then you should consider the mediator pattern.

    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
     import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    
    
    public class ObserverFrame extends JFrame {
    
      Panel1 panel;
      JPanel panel2;
      JLabel label;
    
     //to kick off the example
    public static void main(String args[]){
        new ObserverFrame();        
    }
    
    //constructor of the JFrame
    public ObserverFrame(){
        super("Observer Example");
    
        //the panel that we want to observe
        //notice that we pass a reference to the parent
        panel = new Panel1(this);
        add(panel, BorderLayout.NORTH);
    
        //another panel to be updated when the property changes
        panel2 = new JPanel();
        label = new JLabel("Panel to be updated");
    
        panel2.add(label);
    
        add(panel2, BorderLayout.SOUTH);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(500, 500);
        setVisible(true);
    }
    
    //this method will be called by the panel when the property changes.
    public void trigger(Panel1 panel) {
        label.setText(String.valueOf(panel.getProperty()));
    }
    
    
    //inner class for convenience of the example
    class Panel1 extends JPanel{
        ObserverFrame parent;
        JButton b1;
        private int property;
    
        //accept the parent
        public Panel1(ObserverFrame p){
            this.parent = p;
            b1 = new JButton("Click Me");
            //click the button to change the property
            b1.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e){
                    setProperty(getProperty() * 2); //update property here
                }
            });
            property = 10;
            add(b1);
        }
    
        //the property that we care about
        public int getProperty() {
            return property;
        }
    
        //when the setter is called, trigger the parent
        public void setProperty(int property) {
            this.property = property;
            parent.trigger(this);
        }
    
    
      }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two QTreeWidgetItem that are top level. I want to make the second
I have an app that contains top level folder with subfolders in the app's
I have 10 top-level domains e.g. example1.com, example2.com, example3.com, etc, and each domain has
My application has several independent top-level windows, which all have completely different functions/workflows. I
I have a DIV container that is a CSS class defined on the top
I have a QWidget that contains multiple children. The ultimate goal is to be
I have a top level menu in my ShellView and when selecting a sub
Currently, I'm trying to have a top-level window in Windows Forms with a custom
Good afternoon, I have a quick 'top level' question regarding the usage of Facebook
I have the following setup. The folder itext is in the top level 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.