HELP!! Close a JFrame closes whole app

B

brightoceanlight

I have an application that extends JFrame.

When a user presses a button, a smaller JFrame is also opened.

But when the user clicks on the box with an x in the menu bar of the
smaller JFrame to close the small JFrame, the whole app closes.

How can I fix this problem, so only the smaller JFrame closes and not
the whole app??
 
S

Sebastian Millies

I have an application that extends JFrame.

When a user presses a button, a smaller JFrame is also opened.

But when the user clicks on the box with an x in the menu bar of the
smaller JFrame to close the small JFrame, the whole app closes.

How can I fix this problem, so only the smaller JFrame closes and not
the whole app??

Perhaps the default close operation is not set correctly?
Have a look at setDefaultCloseOperation() in the JFrame API
docs.

-- Sebastian
 
R

Roedy Green

I have an application that extends JFrame.

When a user presses a button, a smaller JFrame is also opened.

But when the user clicks on the box with an x in the menu bar of the
smaller JFrame to close the small JFrame, the whole app closes.

How can I fix this problem, so only the smaller JFrame closes and not
the whole app??

If you won't show us the code we can only guess what you did wrong.
See the generic advice on how to set up JFrames at
http://mindprod.com/jgloss/jframe.html
 
B

brightoceanlight

Thanks for the replies!

I found the error.

I set :

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

for each frame. That's why it was closing.
 
O

Oliver Wong

I have an application that extends JFrame.

When a user presses a button, a smaller JFrame is also opened.

But when the user clicks on the box with an x in the menu bar of the
smaller JFrame to close the small JFrame, the whole app closes.

How can I fix this problem, so only the smaller JFrame closes and not
the whole app??

Don't set the default close operation to be "EXIT_ON_CLOSE".

- Oliver
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top