permaculture playing cards*
The moose likes Swing / AWT / SWT and the fly likes Disabling the 'X' button of JDialog Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Disabling the Watch "Disabling the New topic
Author

Disabling the 'X' button of JDialog

Jeff Wisard
Ranch Hand

Joined: Jan 07, 2002
Posts: 89
Hello,
Does anyone know how to disable (or remove) the 'X' button (or 'close' button) on the title bar of a JDialog? I know how to set it to do nothing (via the setDefaultCloseOperation() method with DO_NOTHING_ON_CLOSE as the parameter), but I want it to look disabled...or not be there at all.
Thanks!
[ April 04, 2002: Message edited by: Jeff Wisard ]

Jeff Wisard<br />Sun Certified Java Programmer (Java 2)<br />Sun Certified Web Component Developer
Thomas Smets
Ranch Hand

Joined: Dec 11, 2001
Posts: 111
In the Java Tutorial there is a simpleExample of JOptionPane

The JOptionPane is a simple JDialog with all you need



Thomas Smets
Just another developper
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

If you're using Java 1.4 you can remove the exit button by calling setUndecorated( true ) and passing it a style of PLAIN_DIALOG.

Here's some example code...


-Nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Jeff Wisard
Ranch Hand

Joined: Jan 07, 2002
Posts: 89
Thanks, Nate. Unfortunately, we are still back in the jdk1.2.2 world. Is there another alternative?
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Nope... the setUndecorated() and setWindowDecorationStyle() methods have just been added with 1.4... In previous JDKs there is no way to change top level components like this...

Perhaps you could extend a JWindow and just draw your own titlebar on the top?

-Nate
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

You can't call setCloseable(FALSE) on a JDialog?
you can disable it by setting "DO_NOTHING_ON_CLOSE" and intercepting the window closing event to do what you need to do there.
Jeff Wisard
Ranch Hand

Joined: Jan 07, 2002
Posts: 89
Yea...this I already know. What I want to do is have the 'X' button disabled...so that it never even generates the event. I want the user to know, just by looking at it, that the 'X' button is disabled.
Better yet, I would like it to not even be available on the title bar.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Disabling the 'X' button of JDialog
 
Similar Threads
JDialog
hide x-Close-Button in a JDialog
Custom Password Dialog
JDialog X Button
How prevent the user closing the Joptionpane by clicking the X in the right end corner