tags:

views:

58

answers:

1

I am currently porting my Android app to a desktop app using Java (Swing, NetBeans). I need a main java window and several pop-up forms for user IO. In the android app I have been using activities, eg: startActivity(anotherActivity). I am currently using a JFrame for each pop-up form in the PC app I have been using setVisible to simulate opening the forms from menu actions and other event logic, but hitting the close button on any of the pop-up forms closes the entire app, not just the form. Should I be using something other than setVisible(true|false)? Should I be using something other than JFrames such as a JPanel or JDialog? Should I override close() on my child forms to do setVisible(false)? Unfortunately, I am learning Java, Swing, and NetBeans on the fly so the best approach to these types of problems is not obvious (to me).

Edit: Why is the auto generated code in initComponents() set to EXIT_ON_CLOSE when the defaultCloseOperation is set to HIDE in the swing form properties?

+2  A: 

You probably want to adjust the default close operation, to just hide the frame instead of quitting the app:

  setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);

Resources

zigdon
I verified that the defaultCloseOperation is set to HIDE in the form properties, but the auto generated code in initComponents() is set to EXIT_ON_CLOSE. Is this a JavaBeans defect? Is there a workaround?
JackN
HIDE is working now. Not getting the EXIT_ON_CLOSE in initComponents any more. Do not know exactly why.
JackN