🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: how to stop exiting, or how are frame decorations disabled?

#671
From: John McGrath [TeamB]
Date: Wed, 12 Jan 2005 03:21
46 lines
3012 bytes
On 1/11/2005 at 4:27:55 PM, J. User wrote:

> > Then add a WindowListener to the JFrame:
> > 
> >     frame.addWindowListener( new WindowAdapter() {
> >         public void windowClosing( WindowEvent event ) {
> >             // Decide whether to dispose the frame, exit, etc.
> >         }
> >     };
> 
> That is how I handle the problem but users then complain if the window
> close decoration is enabled and does nothing. 

I think the "normal" implementation of the "// Decide whether ..." part
would be to check the appropriate conditions (e.g. document changed) and
ask the user if he really wants to exit.  Even if you do not want to give
the user a choice, it still would seem appropriate to display a message
dialog telling the user why you are refusing to exit.  So pressing the
close button would not "do nothing".

> what I'd really like to do is disable (just) the exit frame decoration...
> as far as I can see there is no way to do this. 

AFAIK, there is no standard Java way to disable the close button.  You can
eliminate the close button, along with all of the other frame decorations,
using frame.setUndecorated(true).  Of course, you will then need to create
any decorations that you want, and implement their functionality.

One way to do that would be to use the decorations that can be provided by
the look-and-feel.  Unfortunately, all look-and-feels do not support this.
As far as I know, the Windows and Motif look-and-feels do not support it,
while the Metal look-and-feel does.  I presume that the Ocean
look-and-feel (in JDK 1.5) does also.  If you do that, you can probably
find the close button and disable it.

The other approach would be to write some native code to change the window
decorations and call it using JNI.

-- 
Regards,

John McGrath [TeamB]

---------------------------------------------------
Before sending me e-mail, please read:
    http://www.JPMcGrath.net/newsgroups/e-mail.html
Technical Details
Message-ID: <xn0dx52tjd1ywzu00r@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!gatel-ffm!gatel-ffm!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!news.belwue.de!LF.net!newsgroups.borland.com!not-for-mail
References: <413bca93$1@newsgroups.borland.com> <413c27ba$1@newsgroups.borland.com> <MPG.1c4de4b6f5154587989687@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, or how are frame decorations disabled?
Newsgroups: borland.public.jbuilder.java.swing
References: <413bca93$1@newsgroups.borland.com> <413c27ba$1@newsgroups.borland.com> <MPG.1c4de4b6f5154587989687@newsgroups.borland.com>
User-Agent: XanaNews/1.17.1.2
Message-ID: <xn0dx52tjd1ywzu00r@newsgroups.borland.com>
X-Ref: newsgroups.borland.com ~XNS:00000114
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-15
NNTP-Posting-Host: 141.158.234.226
Date: 11 Jan 2005 19:21:26 -0800
X-Trace: newsgroups.borland.com 1105500086 141.158.234.226 (11 Jan 2005 19:21:26 -0800)
Lines: 46
X-Authenticated-User: jpmcgrath
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!gatel-ffm!gatel-ffm!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!news.belwue.de!LF.net!newsgroups.borland.com!not-for-mail