It's not a secret anymore!*
The moose likes Swing / AWT / SWT and the fly likes To quit window by button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "To quit window by button" Watch "To quit window by button" New topic
Author

To quit window by button

Vipul Tangri
Greenhorn

Joined: Nov 09, 2000
Posts: 11
hi,
i want to quit my frame by button ...
how could i do it?
one more thing, how i donno allow to resize my frame ?ie no maximisation
thx,
vipul
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
You could use the hide() method. If you no longer need to use it again, use dispose(). Both are in the Window class.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

To make your frame non-resizable, use:


Are you trying to close your window with the X button up in the corner, or with a java button on the GUI? If you want to close with the X button you have to add a WindowListener to the window that overrides the windowClosing() method. If you are using another button you have to add an ActionListener to that button.

-Nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Vipul Tangri
Greenhorn

Joined: Nov 09, 2000
Posts: 11
Originally posted by Nathan Pruett:
[B]To make your frame non-resizable, use:


Are you trying to close your window with the X button up in the corner, or with a java button on the GUI? If you want to close with the X button you have to add a WindowListener to the window that overrides the windowClosing() method. If you are using another button you have to add an ActionListener to that button.

-Nate[/B]

hi Nathan,
i tried to close my GUI with the help of a button and i add a windowlistener to that button.
i wrote
public void actionPerformed(ActionEvent e)
{
if e.getSource()==button // button i want to use to close
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
}
but itdidn't work...
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
And what happened when you used hide() or dispose()?
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121



or:



-Nate
Vipul Tangri
Greenhorn

Joined: Nov 09, 2000
Posts: 11
Thx Nate and Stevens....
the button problem is solved as well as resize one...
thx once again..
vipul
 
jQuery in Action, 2nd edition
 
subject: To quit window by button
 
Similar Threads
JFrame problems.....
opening a frame right beneath the calling button
Can we color a Frame.
confusion
JOptionPane Question!