I'm curious, when setting the default close operation for JFrames, should you use JFrame's constants or WindowConstants' constants?

As far as I can tell they're the same. Although, IntelliJ (not tested on other IDE's) prefers WindowConstants' EXIT_ON_CLOSE at least.

So basically my question is, which one should be used? Which do you use? If any, what's the difference?

Recommended Answers

All 3 Replies

JFrame's DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE are inherited from WindowConstants (JFrame implements WindowConstants)

EXIT_ON_CLOSE seems a historical oddity - it was first implemented in JFrame in Java 1.3, but then added to WindowConstants in Java 1.4 anyway.

So the answer to your question is: it makes no difference.

there is significant difference WindowListener is designated for add (code block e.g. closing resources before) control the closing JVM processes in comparing with the JFrame.setDefaultClose....

I don't understand! Why mention WindowListener? The question was about the constant values defined in the two classes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.