Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Disabling the 'X' button of JDialog

 
Jeff Wisard
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Thomas Smets
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the Java Tutorial there is a simpleExample of JOptionPane

The JOptionPane is a simple JDialog with all you need

 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jeff Wisard
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Nate. Unfortunately, we are still back in the jdk1.2.2 world. Is there another alternative?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic