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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:18:52+00:00 2026-06-01T07:18:52+00:00

I have a button that opens up a frame. Is there a way to

  • 0

I have a button that opens up a frame. Is there a way to enable/disable a button depending on whether the frame is open?

Let’s say, if the frame is open, I would like the button to be button.enabled(false). But as soon as the frame is closed, I would like to change it to button.enabled(true).

In my actionPerformed method of the button I do this

JFrame testFrame = new JFrame();
testFrame.setSize(100,100);
testFrame.setVisible(true);

However, I don’t want to open up more than one of these frames at a time. So while the frame that is created by the click of the button is open, I want the button disabled until the frame is closed. (Even if the frame is not visible, I still don’t want to allow another one to be opened)

  • 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-01T07:18:54+00:00Added an answer on June 1, 2026 at 7:18 am

    You probably shouldn’t be opening a dependent window as a JFrame from another GUI. Likely you’re much better off opening a dialog such as a modal or non-modal JDialog or JOptionPane. Please understand that either of these two critters can hold very complex GUI’s. For instance, please have a look here for an example: how-do-you-return-a-value-from-a-java-swing-window-closes-from-a-button

    Also if your dialog variable is a field of your class, then it is created only once and you can’t have two of these windows displayed even if the button to display it is pressed more than once.

    Your code could look something like…

    // testDialog is a JDialog field. and this line is called in 
    // the class constructor.
    JDialog testDialog = new JDialog(theCurrentJFrame, "Dialog Title", false); // true 
                                                                        // if modal
    
    // this line is called in the button's ActionListener.
    testDialog.pack(); // Never set the size of your GUI's. 
                       // Let the layout managers do this for you.
    testDialog.setVisible(true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a button that opens a dialog when clicked. The dialog displays a
I have a button that opens a panel in a popup window and then
I have a datagrid column with a button that opens a modal dialog box
I have a web page with a button that opens up a popup page
I have a parent frame Frame1 that opens a page Page1. From Page1 I
I have a main JFrame. There is a button inside the frame. When I
So I have these buttons in my app that I want to open .PDF
I have a button that when clicked will run a stored procedure on a
I have a button that I'm creating in a UIViewController like so: TOLoginButton* button
I have a button that, when pressed, will add a new HTML row. Within

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.