Article View: borland.public.jbuilder.java.swing
Article #336Re: stopping window close event
From: 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.
Technical Details
Message-ID:
<4303fcda$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newspeer.tds.net!38.119.100.82.MISMATCH!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<43018137$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 111d45,18e74e2743c5a2cd X-Google-Attributes: gid111d45,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Wed, 17 Aug 2005 23:13:42 -0400 From: "Paul Furbacher [TeamB]" <pfurbacher@mac.com> Organization: Reverse Alchemy, Inc. User-Agent: Mozilla Thunderbird 0.8 (Macintosh/20040913) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing Subject: Re: stopping window close event References: <43018137$1@newsgroups.borland.com> In-Reply-To: <43018137$1@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 69.142.222.65 Message-ID: <4303fcda$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1124334810 69.142.222.65 (17 Aug 2005 20:13:30 -0700) Lines: 64 Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newspeer.tds.net!38.119.100.82.MISMATCH!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail