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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:00:12+00:00 2026-05-27T15:00:12+00:00

I am having a bit of problem regarding Swing. I have a JFrame called

  • 0

I am having a bit of problem regarding Swing. I have a JFrame called FrameMain. Inside it is a JPanel called panelChoices.

When FrameMain is called/created, it fills up the panelChoices object with a number of PanelEntries objects, which is a JPanel with a number of JButtons in it (it is a different class that I wrote).

What I want to do is when I click one of the buttons inside the PanelEntries object, I want to destroy/remove FrameMain, along with the rest of it components (including the PanelEntries object that contains the JButton).

I’ve tried using super but it returns the JPanel (the PanelEntries object) that holds the JButton and not FrameMain that holds them all together. How can I achieve this?

EDIT: It seems that I am not clear enough, so here’s a bit more information from my work. I don’t have the actual code right now because I am on a different machine but I hope this will help elaborate my question.

public class FrameMain() {
    private JFrame frameMain;
    private JPanel panelChoices;

    public FrameMain(args) {
        createGUI();
        loadData();
    }

    private void createGUI() {
        JFrame frameMain = new JFrame();
        JPanel panelChoices = new JPanel(new GridLayout(1,1));
        frameMain.add(panel);
        // removed formatting and other design codes since they are not important.
        pack();
    }

    private void loadData() {
        boolean available;
        for (int i = 1; i <= 10; i++) {
            // do some if/else and give value to boolean available
            PanelEntries panel = new PanelEntries(i, available);
            frameMain.add(panel);
            // more code here to handle data.
        }
    }
}

public class PanelEntries() extends JPanel {

    public PanelEntries(int num, boolean avb) {
        JButton button = new JButton("Button Number " + num);
        button.setEnabled(avb);
        add(button);
        // add action listener to created button so that it calls 'nextScreen()' when clicked.
        // more code
        pack();
    }

    private void nextScreen() {
        // destroy/dispose MainFrame here.
        // See Notes.
        AnotherFrame anotherFrame = new AnotherFrame();
    }
}

Notes:

  1. All classes are inside their own .java file.
  2. I need to know how to dispose FrameMain from the button inside the PanelEntries object, not just disposing a JFrame.
  • 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-27T15:00:13+00:00Added an answer on May 27, 2026 at 3:00 pm

    As per the given information,

    1. If you want to exit the application, its not a big deal use System.exit(0); 🙂

    2. If you mean to dispose the frame, jframe.dispose();

    3. If you want to remove a componet / all components you can use .remove(Component) / .removeAll() etc

    If this did not help, please re-write your question with more information.

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

Sidebar

Related Questions

Having a bit of a problem creating an instance of an object. Bear in
I'm having a bit of a problem. I have a datatable in the parent
I'm having a bit of a problem here. We have 2 urls let me
I'm having a bit of problem with casting and datagrids. I have a LINQ
Having a bit of a problem, Due to the source-control set-up we use, each
I am having a bit of a problem. I get a RAW char* buffer
I'm having a bit of a problem with converting the result of a MySQL
I'm having a bit of a problem using FieldOffset correctly with arrays. The code
I'm having a bit of a problem with getting JBoss working across networks. As
I'm having a bit of a problem figuring out how to get the X/Y

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.