Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Overriding close functionality in a JDialog

Status
Not open for further replies.

msloan

Programmer
May 30, 2001
39
US
Hey,

I am trying to either disable or override the close box in the top right corner of a JDialog. Pretty much, I don't want to give the user the ability to exit the form.

I have added a WindowListener and tried a couple of different things. And I have also tried setDefaultCloseOperation() with the different constants. Not much luck so far.

Any ideas?

Thanks
Matt
 
I have used the setDefaultCloseOperation(DO_NOTHING_ON_CLOSE) with success in the past with JFrames, though not tried with a dialog but it should be okay.

The possible choices are:
DO_NOTHING_ON_CLOSE - do not do anything - require the program to handle the operation in the windowClosing method of a registered WindowListener object.
HIDE_ON_CLOSE - automatically hide the dialog after invoking any registered WindowListener objects
DISPOSE_ON_CLOSE - automatically hide and dispose the dialog after invoking any registered WindowListener objects
The value is set to HIDE_ON_CLOSE by default.

HTH

Scrat
 
PS, I've tried this and it works for me:

class MyJDialog extends JDialog {
MyJDialog(Frame f) {
super(f, true);
setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
}
}

Also try removing your listener; it might be overriding the JDialog?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top