Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #4814
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe13.iad.POSTED!83aa503d!not-for-mail |
|---|---|
| From | Daniel Pitts <newsgroup.nospam@virtualinfinity.net> |
| User-Agent | Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:8.0) Gecko/20111105 Thunderbird/8.0 |
| MIME-Version | 1.0 |
| Newsgroups | comp.lang.java.gui |
| Subject | Re: cleaning up very carefully |
| References | <cleaning-20111207080049@ram.dialup.fu-berlin.de> |
| In-Reply-To | <cleaning-20111207080049@ram.dialup.fu-berlin.de> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 8bit |
| Lines | 52 |
| Message-ID | <pFUDq.17253$LO2.10029@newsfe13.iad> (permalink) |
| X-Complaints-To | abuse@newsrazor.net |
| NNTP-Posting-Date | Thu, 08 Dec 2011 01:45:57 UTC |
| Date | Wed, 07 Dec 2011 17:45:57 -0800 |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.gui:4814 |
Show key headers only | View raw
On 12/6/11 11:24 PM, Stefan Ram wrote:
> Executive Summary of my question: Can you dispose a Swing
> GUI component (or all of the Swing GUI) while processing an
> event generated from this very GUI component?
>
> More elaborated:
>
> You all know
>
> frame.setDefaultCloseOperation( javax.swing.JFrame.EXIT_ON_CLOSE );
Alternatively there is the DISPOSE_ON_CLOSE, which sounds like you want
instead of EXIT_ON_CLOSE.
>
> , but I have found that the EDT (and thus the JVM) will also
> terminate once all disposable Swing components are disposed.
>
> So, when I get a »QUIT« command (i.e., from the application menu),
> I dispose all Swing components, and the application exits. I like
> this, because when I forget to dispose a single Swing component
> in my cleanup, this error will immediatly be observable, because
> in this case, the application will not exit anymore.
>
> Now, I had no idea, whether it is OK to dispose the whole view of
> the Swing application, including the JFrame and the very QUIT
> menu entry whose message I am just processing during the processing
> of the message from that menu entry itself. When I will return to
> Swing, will Swing be shocked to learn that the GUI component
> whose message was just being processed does not exist anymore?
> Does it need this component to finish the processing of an event
> that was created by this component. (After all, a reference to
> the component might still be contained in the event.)
>
> So I tried to be very careful and do one indirection as follows:
>
> if( message instanceof QuitMainCommand )
> { javax.swing.SwingUtilities.invokeLater
> ( new java.lang.Runnable()
> { public void run()
> { MainFrame.this.dispose(); }} ); }
>
> This is the code for the QUIT menu item. The »MainFrame.this.dispose()«
> will dispose the JFrame and the menu including the QUIT menu item, whose
> message I am just processing. Because, I do not know whether this is
> legal, I call my dispose code indirectly via invokeLater. But is this
> really necessary?
>
> BTW: I am aware that »instanceof« can be a code smell. I have designed
> a hierarchy of commands, and for the moment I am not aware of a better
> solution. I am (ab)using the Java class system to store a tree of
> commands, using »instanceof« to test for subentries of a tree.
>
Back to comp.lang.java.gui | Previous | Next | Find similar
Re: cleaning up very carefully Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2011-12-07 17:45 -0800
csiph-web