Remove "X" button in Swing JDialog

Is there a way to remove the close button ("X") from the JDialog title bar?


You can remove the whole dialog title by calling dialog.setUndecorated(true) but this means that the dialog can't be moved anymore.

You can also execute dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE) to prevent that the button does anything.

Besides that, I don't think that there's a way to remove the X completely.


I believe that you can call dialog.setUndecorated(true) to remove the title bar. Not sure about just the 'X' though.

Removing the 'X' may not be a great idea, though, as you want your users to be able to close the dialog easily.

Best bet is to control what happens when the users clicks the 'X' by using dialog.setDefaultCloseOperation or a WindowListener.