Thread View: borland.public.jbuilder.java.swing
6 messages
6 total messages
Started by andy dingfelder
Mon, 06 Sep 2004 02:25
how to stop exiting
Author: andy dingfelder
Date: Mon, 06 Sep 2004 02:25
Date: Mon, 06 Sep 2004 02:25
11 lines
1299 bytes
1299 bytes
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? I have ajMenuFileExit_actionPerformed(ActionEvent e) method to do this from the file menu but the X icon is a workaround that I need to trap also. (Im doing work with serial portsd and want to prevent them from exiting before the device is unplugged) Thanks for any advice, Andy
Re: how to stop exiting
Author: Tor Iver Wilhelmsen [TeamB]
Date: Mon, 06 Sep 2004 07:06
Date: Mon, 06 Sep 2004 07:06
10 lines
1341 bytes
1341 bytes
"andy dingfelder" <dingfeldera@landcareresearch.co.nz> writes: > 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? Set the JFrame's default close operation to DO_NOTHING_ON_CLOSE, and add a WindowListener where you do your processing in windowClosing(). Remember to call hide() or System.exit() since you become responsible for actually closing the window.
Re: how to stop exiting
Author: John McGrath [TeamB]
Date: Mon, 06 Sep 2004 09:02
Date: Mon, 06 Sep 2004 09:02
26 lines
1615 bytes
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
Re: how to stop exiting, or how are frame decorations disabled?
Author: J. User
Date: Tue, 11 Jan 2005 21:27
Date: Tue, 11 Jan 2005 21:27
23 lines
1972 bytes
1972 bytes
In article <413c27ba$1@newsgroups.borland.com>, ng-b@JPMcGrath.net says...
> 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.
> }
> };
That is how I handle the problem but users then complain if the window close decoration is enabled and does
nothing. I can make it equivalent to calling the existing exit function from the file menu but 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. Am I
just not finding it in the docs or is it really not possible from java?
Re: how to stop exiting, or how are frame decorations disabled?
Author: John McGrath [TeamB]
Date: Wed, 12 Jan 2005 03:21
Date: Wed, 12 Jan 2005 03:21
46 lines
3012 bytes
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
Re: how to stop exiting, or how are frame decorations disabled?
Author: J. User
Date: Wed, 12 Jan 2005 21:38
Date: Wed, 12 Jan 2005 21:38
33 lines
2531 bytes
2531 bytes
In article <xn0dx52tjd1ywzu00r@newsgroups.borland.com>, ng-b@JPMcGrath.net says...
> 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
Yes, I believe I went on to describe something like that.
> 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".
Perhaps I should have said "accomplishes nothing useful"
> > 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
Too bad... seems like something that ought to be there. Oh well... at least
now I know not to waste more time looking for it - 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