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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:46:16+00:00 2026-05-22T20:46:16+00:00

I have simple Swing GUI with main window JFrame and its main panel derive

  • 0

I have simple Swing GUI with main window JFrame and its main panel derive from JPanel. The panel has some buttons that can be clicked and generate events.

I want these events affect data stored in JFrame because it is my main application – it has some queues for thread, open streams and so on.

So how do I make my button in panel invoke callbacks in its parent frame? What is best practice of this for Java/Swing?

  • 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-22T20:46:17+00:00Added an answer on May 22, 2026 at 8:46 pm

    To invoke methods in the parent frame you need a reference to the parent frame. So your JPanel’s constructor can be declared like this:

     public MyPanel(MyFrame frame){
        super();
        this.frame = frame;
        //the rest of your code
    }
    

    And in the JFrame you invoke this constructor like this:

      panel = new MyPanel(this);//this refers to your JFrame
    

    In the event handlers attached to your buttons you now have access to the frame and can invoke the various methods as needed.

      button1.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent e){
               //do some stuff
               frame.someMethod();//invoke method on frame
               //do more stuff
          }
      });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple Swing GUI with just a JTetxtArea. I am trying
i have a simple swing gui where there are two text fields one for
I have a simple problem with my JPanel / Gridbaglayout: import javax.swing.*; import java.awt.*;
I have a simple Java Swing GUI Form with a browse button. The browse
I have a small (500kb) swing applet that displays very simple/limited set of small
I have simple regex \.*\ for me its says select everything between and ,
I have simple SSIS package which reads data from flat file and insert into
I have simple HTML code with some JavaScript. It looks like: <html> <head> <script
I have simple SSIS package where I import data from flat file into SQL
I am building a swing application. At some point, I have to start an

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.