Skip to main content

setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE) - compiles but fails

3 replies [Last post]
stevends
Offline
Joined: 2006-11-07
Points: 0

Scenario:

An application, developed with Java 5, shows a small JDialog before the main application JFrame is launched.
If the user closes the dialog, the application is terminated.

To obtain this behavior, the default close operation is set to EXIT_ON_CLOSE. Although the API doesn't mention this as a valid option, the field is inherited from the javax.swing.WindowConstants class and it works just fine on the Java 5 platform.

I tried to migrate the application to Java 6. The field is still inherited (of course), the source compiles without errors but when the application is launched, following error is displayed:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: defaultCloseOperation must be one of: DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE, or DISPOSE_ON_CLOSE

Seems logic to me since apparently that option shouldn't be used for a JDialog, but it's hard to migrate an application if source compliancy gives no guarantees on runtime compliancy.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
trembovetski
Offline
Joined: 2003-12-31
Points: 0

Hello,

this is an intended change covered by this bug id:
5109681: JDialog.setDefaultCloseOperation() needs to better document its arguments
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5109681

> Although the API doesn't mention this as a valid option, the field is inherited from the javax.swing.WindowConstants class and it works just fine on the Java 5 platform.

Actually, it didn't: it just didn't do anything, the value was ignored. The effect of closing was most likely due to some side-effect of some listener you had installed on the dialog.

This value wasn't supported, and in jdk6 it was decided to guard against invalid values. Apparently, one used to be able to pass any value to setDefaultCloseOperation(), but invalid ones were ignored.

Thanks,
Dmitri

stevends
Offline
Joined: 2006-11-07
Points: 0

Thanks for the info!

trembovetski
Offline
Joined: 2003-12-31
Points: 0

Thanks passed to Shannon from the Swing team who explain this to me =)

Dmitri