[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Using setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) with multiple JFrame's

Posted on 2006-03-26
8
Medium Priority
?
2,042 Views
Last Modified: 2010-05-18
Hi!

I am running an application which uses multiple JFrame's running in separate threads. To close a JFrame I have set:
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

The problem now is, that closing one JFrame closes all JFrame's, and I only want to close the selected JFrame.

How do I solve that?

Regards,
Jesper
0
Comment
Question by:jespersahner
  • 3
  • 3
  • 2
8 Comments
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 16293570
That causes the JVM instance to end when the frame is closed.

Generally, you'd just add a WindowListener to your JFrame, and then either destroy() it, or hide it using setVisible(false).
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 16293575
An example:

JFrame fr ;  // global
.
.
WindowListener l = new WindowAdapter()
{
    public void windowClosing( WindowEvent evt )
    {
        // close here
        fr.setVisible( false ) ;
        // or fr.destroy() ;    <-- probably the best one to use
    }
} ;
fr.addWindowListener( l ) ;
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 400 total points
ID: 16293628
Just use

JFrame.DISPOSE_ON_CLOSE
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 86

Expert Comment

by:CEHJ
ID: 16293629
i.e.

setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 16293645
Oh. That's easier :)
0
 

Author Comment

by:jespersahner
ID: 16293646
->CEHJ: Thanks! Reading the manual often solves the problem, which I didn't in this case :-))
0
 

Author Comment

by:jespersahner
ID: 16293648
-> InteractiveMind: Thanks for your input anyway :-)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16293657
:-)
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month19 days, 1 hour left to enroll

834 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