Java GUI: wait for a JFrame to return before continuing to do other stuff

Posted on 2005-05-05
Last Modified: 2008-02-26
Here's my question. It's probably a common one. I'm in MyFrame2 and executing doSomething function. When I create MyFrame1 instance, there's a fame popping up the screen asking for the user's input. I want to get the input for doSomethingB area so I need to wait till MyFrame1 instance is done. Any good approach for this? I just need hints.

class MyFrame1 extends JFrame(){

class MyFrame2 extends JFrame(){
  public void doSomething(){
    //do something A
    MyFrame1 frame = new MyFrame1();
    //do something B

It should've been JDialog or something. It's too late to change it now as the architecture was done by previous programmers. =/

thanks in advance,
Question by:oracle1998
    LVL 35

    Expert Comment

    Errr...  you could kick off the other frame in a thread and keep checking in your main thread to see if the frame has closed...

    But this is a horrible hack...

    You want to change the JFrame to a JDialog and set it as modal

    That's the only nice solution... :-(


    Accepted Solution

    To make your frame modal:

      MyFrame1 frame;
      Runnable modalFrame = new Runnable() {
         public void run() {
             frame = new MyFrame1();

      public void doSomething(){
        //do something A
        //do something B

    Author Comment

    Thanks so much. That's pretty sleek. =)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
    INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now