aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Enable/Disable Window Close X Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Enable/Disable Window Close X" Watch "Enable/Disable Window Close X" New topic
Author

Enable/Disable Window Close X

Emerson Dunne
Greenhorn

Joined: Oct 19, 2000
Posts: 28
I have an application in which I enable and disable the Exit menuItem on the File menu according to the state of the system.
However, currently a user might click the Close "X" button in the upper right hand corner of my JFrame. I'd like to enable and disable this button when I enable/disable the Exit menuItem.
Does anyone know how to do this?
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
Originally posted by Emerson Dunne:
I have an application in which I enable and disable the Exit menuItem on the File menu according to the state of the system.
However, currently a user might click the Close "X" button in the upper right hand corner of my JFrame. I'd like to enable and disable this button when I enable/disable the Exit menuItem.
Does anyone know how to do this?

may be this is'nt what u want. You must be having a WindowListener to close the window when X is clicked.
In any case why don't u try removing and adding the listener on the fly? in an event of your interest.
But the X w'd be visible though!
karthik.
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Emerson,
No you can't visually enable or disable it. As stated by Karthik, you can use the callback. You will never want to remove it though because the default action is to remove the window. Since you want to use some logic on when to remove the window your listener will always be required! The code below illustrates the feature.

Enjoy,
Manfred.
Emerson Dunne
Greenhorn

Joined: Oct 19, 2000
Posts: 28
Thanks for the replies. Manfred, I am essentially doing what you suggested... and it will work just fine; however, I was hoping to communicate visually that clicking the [X] will have no effect when it truely will have no effect.
Thanks again for the replies.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Enable/Disable Window Close X
 
Similar Threads
Stopping an InternalFrame from closing
How to make an Expanding Menu
disable CLOSE (X) button on a popup window
hide x-Close-Button in a JDialog
Disabling the close (X) button of the browser