🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #1015

Re: how to stop exiting

#1015
From: John McGrath [TeamB]
Date: Mon, 06 Sep 2004 09:02
26 lines
1615 bytes
On 9/5/2004 at 10:25:23 PM, andy dingfelder wrote:

> How can I trap the exit icon (the upper right X) actions so that I can
> do some logic first and under some conditions display a message instead
> of exiting?

Disable the automatic closing of the JFrame using

    frame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE );

Then add a WindowListener to the JFrame:

    frame.addWindowListener( new WindowAdapter() {
        public void windowClosing( WindowEvent event ) {
            // Decide whether to dispose the frame, exit, etc.
        }
    };

-- 
Regards,

John McGrath [TeamB]

---------------------------------------------------
Before sending me e-mail, please read:
    http://www.JPMcGrath.net/newsgroups/e-mail.html
Technical Details
Message-ID: <413c27ba$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!news-out.ntli.net!newsrout1.ntli.net!news-in.ntli.net!ntli.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <413bca93$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 111d45,76f888c29044beef
X-Google-Attributes: gid111d45,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "John McGrath  [TeamB]" <ng-b@JPMcGrath.net>
Subject: Re: how to stop exiting
Newsgroups: borland.public.jbuilder.java.swing
References: <413bca93$1@newsgroups.borland.com>
User-Agent: XanaNews/1.16.4.2
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-15
NNTP-Posting-Host: 141.158.35.112
Message-ID: <413c27ba$1@newsgroups.borland.com>
Date: 6 Sep 2004 02:02:50 -0700
X-Trace: newsgroups.borland.com 1094461370 141.158.35.112 (6 Sep 2004 02:02:50 -0700)
Lines: 26
X-Authenticated-User: jpmcgrath
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!news-out.ntli.net!newsrout1.ntli.net!news-in.ntli.net!ntli.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail