tags:

views:

1970

answers:

4

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

A: 

At a guess, set it to be PL&F decorated and remove the component by name.

Tom Hawtin - tackline
+1  A: 

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.

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

Huxi
+2  A: 

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.

thedude19
+1  A: 

As of Java 1.6 (AKA Mustang or Java 6), you can not disable or remove the close button on a Window. You can remove/disable the maximize button with frame.setResizable(false) and you can remove the minimize and maximize buttons by using a JDialog instead of anything else. You can remove the title bar, borders, and buttons with frame.setUndecorated(true), and you can have full control over the visibility of all buttons in the title bar (while losing some cross-platform compatibility and OS integration) with frame.setDefaultLookAndFeelDecorated(true) (assuming it's a JFrame or JDialog). This is all the control I see possible with the current JDK.

Supuhstar
This is "will not fix" on [bug parade](http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5085932).
Geoffrey Zheng