This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Swing / AWT / SWT and the fly likes Disabling The Maximize Box And The Close Box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Disabling The Maximize Box And The Close Box" Watch "Disabling The Maximize Box And The Close Box" New topic
Author

Disabling The Maximize Box And The Close Box

Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 689

Is there a way to disable the maximize button in a Window?

Is there also a way to disable the close box on a modal JDialog and force the user to use a JButton to dismiss the dialog (yet still have a title bar)?

Kaydell
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Is there a way to disable the maximize button in a Window?
You can use the index to look up the setResizable method (links at top of any api
page) to find which classes have it. Frame and Dialog yes, Window no.
Is there also a way to disable the close box on a modal JDialog and force the user to use
a JButton to dismiss the dialog (yet still have a title bar)?

Probably. You might have to write some plaf code.
Other options:
1 — use a JWindow or undecorated JFrame and add or draw a "title bar"
2 — use a JOptionPane which will return null if the dialog is disposed with the close button
3 — add a WindowListener to the dialog and do what you need before the dialog is disposed.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> Is there also a way to disable the close box on a modal JDialog

if you just want to disable the 'X'
dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);

or do you want to remove the 'X'?
Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 689


< Is there a way to disable the maximize button in a Window?

...look up the setResizable method...


Thanks, that worked. Now the Maximize box is still in my title bar, but it's disabled, The Iconify box was already disabled because I'm using a JDialog instead of a JFrame.
Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 689

>> Is there also a way to disable the close box on a modal JDialog

> if you just want to disable the 'X'
> dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);

> or do you want to remove the 'X'?

I did want to entirely remove the close box, but setting the default close operation is good stuff. Now I get a windowClosing WindowEvent and my program has control.

Also, for my JFrames that need to save data to the file-system or to a database, now get notified via the windowClosing() WindowEvent and I get a chance to save.

Kaydell
[ May 24, 2007: Message edited by: Kaydell Leavitt ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Disabling The Maximize Box And The Close Box