Bick
Bick

Reputation: 18511

Java - is there a way to hide the close button in a swing application?

is there a way to hide the close button in a swing application?

I know I can set JFrame.DO_NOTHING_ON_CLOSE but is there a way to eliminate it completely?

if I write setUndecorated(true) I get
IllegalComponentStateException - the frame is displayable

Upvotes: 7

Views: 2188

Answers (1)

Dhruv Gairola
Dhruv Gairola

Reputation: 9182

Using frame.setUndecorated(true) while the frame has already been displayed leads to an error as this is not allowed in the API. Instead, use frame.setUndecorated(true) before you set frame.setVisible(true). This should solve your error:

IllegalComponentStateException - the frame is displayable

If you are successful, the close button will be hidden.

Upvotes: 6

Related Questions