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
posted
0
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
posted
0
> 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);
< 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.
>> 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.