Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1328
  • Last Modified:

Closing a JFrame window

Hi,

I have a JFrame window. Is there any command that closes the window, (not hide() or dispose()), a command that is equivalent to the user pressing the top right 'X' button.
0
deniX23
Asked:
deniX23
  • 2
  • 2
  • 2
1 Solution
 
CEHJCommented:
What would be wrong with dispose btw?
0
 
deniX23Author Commented:
In the window i  have a menu with "close" in it and i want it to act like the top right "X" button:

If the person creating the window uses setDefaultCloseOperation with paramater EXIT_ON_CLOSE, then using "dispose()" when the user clicks "close" won't work (because it won't do the "exit on close" like the "X" would of), on the other hand i can't do system.exit() when the user clicks "close" because maybe the user didnt set EXIT_ON_CLOSE, i cant assume he did or didnt.
0
 
CEHJCommented:
>>the user didnt set EXIT_ON_CLOSE

Isn't it you the programmer who's setting that, not the user?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
objectsCommented:
use this:


switch (frame.getDefaultCloseOperation())
{
   case JFrame.EXIT_ON_CLOSE: System.exit(); break;
   case JFrame.HIDE_ON_CLOSE: frame.hide(); break;
   case JFrame.DISPOSE_ON_CLOSE: frame.dispose(); break;

}

0
 
deniX23Author Commented:
By user i meant another programmer using my frame class.
Anyway, thanks objects that's pretty much equivalent to what i needed.
0
 
objectsCommented:
:)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now