-1

I have two JFrames:

  • ApplicationsJFrame, which is my Main, and
  • InsertApplicationsForm.

I'm setting the InsertApplicationsForm visible by clicking a Button in my ApplicationsJFrame.

Every time I'm closing the InsertApplicationsForm the ApplicationsJFrame also closes, but the Program is still running, same when I minimize InsertApplicationsForm, ApplicationsJFrame minimizes, but wont maximize anymore...

ApplicationsJFrame:

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("T-AMS");
setFocusableWindowState(false);

InsertApplicationsForm:

public class InsertApplicationForm extends javax.swing.JFrame {

    /**
     * Creates new form InsertApplicationForm
     */
    public InsertApplicationForm() {
        initComponents();
    }

[...]

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Insert Application")
addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

private void formWindowClosed(java.awt.event.WindowEvent evt) {                                  
        ApplicationsJFrame.insert = false;
    }

Open InsertApplicationsForm:

new InsertApplicationForm().setVisible(true);
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • How do you create the `InsertApplicationsForm`? Do you specify the main frame as parent? Also check for any `WindowListener` or `WindowStateListener`. See http://docs.oracle.com/javase/tutorial/uiswing/events/windowlistener.html – Aaron Digulla Feb 18 '15 at 16:20
  • edited it. I only added some Textfields and labels since creating the Form – Denis Hartwood Feb 18 '15 at 16:27
  • That's odd. If you don't pass the main frame as parent into `InsertApplicationForm`, the two frames should be completely independent; minimizing one should not affect the other. Which OS? Did you check for any Window listeners? – Aaron Digulla Feb 18 '15 at 16:29
  • Just talked to a friend that i just dont get it because the frames should be independent.... -.- OS is Windows 7 – Denis Hartwood Feb 18 '15 at 16:31
  • Got a listener which sets a variable in the other frame so i can check if the frame is opened..... did exactly the same in my other programs, never was a problem – Denis Hartwood Feb 18 '15 at 16:35
  • Okay, I'm out of ideas. Maybe add a Window listener to the main frame to see what events it does receive; that might give you clue what is going on. You can also use `new Exception().printStackTrace();` in the event listener to see who calls the code. **Don't set breakpoints** in window listeners, your application, IDE or Windows can hang if you do. – Aaron Digulla Feb 18 '15 at 16:49
  • I don't see anything here that could cause such a problem, unless `ApplicationdJFrame.insert` plays a role in the issue. Please show more code – Vince Feb 18 '15 at 17:08
  • 1) See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) 2) For better help sooner, post an [MCVE](http://stackoverflow.com/help/mcve) (Minimal Complete Verifiable Example) or [SSCCE](http://www.sscce.org/) (Short, Self Contained, Correct Example). – Andrew Thompson Feb 18 '15 at 22:58

1 Answers1

0

You should just add the EXIT_ON_CLOSE constant int to your main JFrame. Instead, add a WindowListener to your temporal Frames:

//Suppose you have a custom Frame in your Form class
class InsertApplicationsForm extends JFrame{
//Some stuff
//...

public InsertApplicationsForm(){
//Implement
    //DO NOT ADD setDefaultCloseOperation
setVisible(true);
}

addWindowListener(new WindowAdapter(){

     @Override
    public void windowClosing(WindowEvent e){
        InsertApplicationsForm.this.dispose();
    }

});

}

So in your main class, or method, event, whatever just call this:

new InsertApplicationsForm();

And will automatically open a new JFrame, which you can close and not affecting the main or other Frames. You can even instance multiple of this class Frames and closing won't affect other ones.

Ramses Asmush
  • 134
  • 1
  • 4
  • 10
  • Still doesnt work, i think i'll just have to rewrite the program -.- Thanks for all your help! I wrote a lot of programs with many different forms... never had a problem like this before... – Denis Hartwood Feb 19 '15 at 07:09