Thread View: borland.public.jbuilder.java.swing
5 messages
5 total messages
Started by dingfelder
Tue, 16 Aug 2005 06:01
stopping window close event
Author: dingfelder
Date: Tue, 16 Aug 2005 06:01
Date: Tue, 16 Aug 2005 06:01
16 lines
1376 bytes
1376 bytes
I am trying to make my application ignore clicks on the X in the top right. I have read on the web that you do this via:
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
Other posts have said you also do:
addWindowListener( new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.out.println("exit was pressed");
}
});
When I do these both in my JFrame, the windowClosing event does indeed get called because I see the message, but then it goes ahead and exits.
How can I make it NOT exit?
Re: stopping window close event
Author: Paul Furbacher [TeamB]
Date: Tue, 16 Aug 2005 13:55
Date: Tue, 16 Aug 2005 13:55
41 lines
2306 bytes
2306 bytes
dingfelder wrote:
> I am trying to make my application ignore clicks on the X in the
> top right. I have read on the web that you do this via:
>
> setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
>
> Other posts have said you also do:
>
> addWindowListener( new WindowAdapter() { public void
> windowClosing(WindowEvent e) { System.out.println("exit was
> pressed"); } });
>
> When I do these both in my JFrame, the windowClosing event does
> indeed get called because I see the message, but then it goes ahead
> and exits.
>
> How can I make it NOT exit?
I don't think you can intercept and cancel the window
closing event. Perhaps all you can do is set the
frame to be visible again. Annoying, but unless you
change the container to a dialog box, for which you
do get a chance to cancel an attempt to close, you
are stuck ... unless someone knows some other trick.
--
Paul Furbacher (TeamB)
Save time, search the archives:
http://info.borland.com/newsgroups/ngsearch.html
Is it in Joi Ellis's Faq-O-Matic?
http://www.visi.com/~gyles19/fom-serve/cache/1.html
Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.
Re: stopping window close event
Author: dingfelder
Date: Wed, 17 Aug 2005 21:17
Date: Wed, 17 Aug 2005 21:17
16 lines
1633 bytes
1633 bytes
>I don't think you can intercept and cancel the window >closing event. Perhaps all you can do is set the >frame to be visible again. Annoying, but unless you >change the container to a dialog box, for which you >do get a chance to cancel an attempt to close, you >are stuck ... unless someone knows some other trick. >-- >Paul Furbacher (TeamB) You mention setting the frame visible again... this seems to me to imply that the window frame has not exited bu just become invisible. If this is true, then I could deal with that... although I assume the app might flicker when becoming visible? If this is not, then I assume all the data the user has entered would dissipear which is not good.
Re: stopping window close event
Author: Kevin Dean [TeamB]
Date: Thu, 18 Aug 2005 02:49
Date: Thu, 18 Aug 2005 02:49
28 lines
1795 bytes
1795 bytes
dingfelder wrote: > How can I make it NOT exit? A crude way to do it is throw an exception; that's the only thing I know of that stops a window closing event. If you want to take control of the closing event, then you can do the following: myFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); and then write code elsewhere (e.g. in a button handler) that calls either hide() or dispose(), depending on what you want to do with the frame when you're done. -- Kevin Dean [TeamB] Dolphin Data Development Ltd. http://www.datadevelopment.com/ NEW WHITEPAPERS Team Development with JBuilder and Borland Enterprise Server Securing Borland Enterprise Server http://www.datadevelopment.com/papers/index.html Please see Borland's newsgroup guidelines at http://info.borland.com/newsgroups/guide.html
Re: stopping window close event
Author: Paul Furbacher [TeamB]
Date: Thu, 18 Aug 2005 03:13
Date: Thu, 18 Aug 2005 03:13
64 lines
3268 bytes
3268 bytes
dingfelder wrote:
> I am trying to make my application ignore clicks
> on the X in the top right. I have read on the web
> that you do this via:
>
> setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
>
> Other posts have said you also do:
>
> addWindowListener( new WindowAdapter() {
> public void windowClosing(WindowEvent e) {
> System.out.println("exit was pressed");
> }
> });
>
> When I do these both in my JFrame, the windowClosing
> event does indeed get called because I see the message,
> but then it goes ahead and exits.
>
> How can I make it NOT exit?
Actually, I didn't read your message carefully enough.
With the defaultCloseOperation property set to
DO_NOTHING_ON_CLOSE, the frame does not close unless
you have written code in the windowClosing handler
to actually hide it [setVisible(false)]. So, if
you are seeing the frame close, it's because somewhere
in your code, you are indeed hiding the window, or
calling System.exit(0).
(I just did a test of this by creating a new project,
adding a single frame which has a main() method.
I added a handler for windowClosing as you show above.
I added a "Quit" button which when pushed invokes System.exit().
That is, I double-clicked on the button in the UI Designer
and in the actionPerformed() method which JBuilder generated,
I wrote "System.exit(0);"
With the defaultCloseOperation set as above, nothing
happens when the "X" in the title bar of the window
is pressed except to print out the message to JBuilder's
Message Pane.
Only when I press the "Quit" button does the window close.
However, the windowClosing() event is not generated when
I hit the "Quit" button. (This is just as expected.)
If you want to confirm whether to quit, you have to
do that in the button's actionPerformed() handler.
--
Paul Furbacher (TeamB)
Save time, search the archives:
http://info.borland.com/newsgroups/ngsearch.html
Is it in Joi Ellis's Faq-O-Matic?
http://www.visi.com/~gyles19/fom-serve/cache/1.html
Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads