Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #3157

Re: Singletons and Swing

Path csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!nx02.iad01.newshosting.com!newshosting.com!novia!news-out.readnews.com!news-xxxfer.readnews.com!news-out.news.tds.net!newsreading01.news.tds.net!86597e80!not-for-mail
From "Peter Duniho" <peter.duniho@THRWHITE.remove-dii-this>
Subject Re: Singletons and Swing
Message-ID <op.t6i95v1c8jd0ej@petes-computer.local> (permalink)
X-Comment-To comp.lang.java.programmer
Newsgroups comp.lang.java.gui
In-Reply-To <0a12ac8a-5aff-411b-8934-f855022e5466@e10g2000prf.googlegroups.com>
References <0a12ac8a-5aff-411b-8934-f855022e5466@e10g2000prf.googlegroups.com>
Content-Type text/plain; charset=IBM437
Content-Transfer-Encoding 8bit
X-Gateway time.synchro.net [Synchronet 3.15a-Win32 NewsLink 1.92]
Lines 47
Date Wed, 27 Apr 2011 15:43:14 GMT
NNTP-Posting-Host 96.60.20.240
X-Complaints-To news@tds.net
X-Trace newsreading01.news.tds.net 1303918994 96.60.20.240 (Wed, 27 Apr 2011 10:43:14 CDT)
NNTP-Posting-Date Wed, 27 Apr 2011 10:43:14 CDT
Organization TDS.net
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.gui:3157

Show key headers only | View raw


  To: comp.lang.java.programmer
On Thu, 14 Feb 2008 13:20:53 -0800, Jason Cavett <jason.cavett@gmail.com>  
wrote:

> I am attempting to design a menu system for an application I am
> writing.  In it, I want an InsertMenu that exists within multiple
> different menus.  Currently, I am attempting to do this by making the
> InsertMenu a singleton.  This is causing a weird issue.
>
> I currently have two menus that hold the InsertMenu - a MainMenu and a
> TreePopupMenu.  The InsertMenu should be contained within both of
> those.  However, it seems as though it can only be in one menu at a
> time.  For example, if the TreePopupMenu has been created (which
> happens after I've opened up a new project), the InsertMenu completely
> disappears (with no errors or warnings) from the MainMenu.
>
> Is it possible to accomplish what I'm trying to do?

I doubt it.  Don't take my word for it, as I'm inexperienced with Java.   
But given that a Java menu is a component and has a parent, and given that  
as far as I know in Java a component can have only one parent at a time  
(that's a common enough restriction in a wide variety of parent-child code  
designs and while I haven't seen an explicit statement to that effect in  
the Java docs, it may exist and/or simply be implied), your menu can only  
be a child of any one menu at a time.

You could probably change your singleton so that it's not actually a  
menu.  Instead, it would be a sort of menu factory that keeps track of its  
actual menu instances.  It's not really clear why you want this menu to be  
a singleton anyway, but one possibility is that the menu is changeable and  
you want to be able to have just a single instance that changes and have  
those changes reflected anywhere the menu is used.  If so, you can't do it  
directly, but making your singleton a factory that tracks the created  
menus would allow the factory to also update all of the created menus  
appropriately as needed (assuming those changes always go through the  
factory, of course).

Not relevant to anything, but I'm also a little puzzled as to the reason  
for having the "InsertMenuHolder" class.  Why not just have a private  
static InsertMenu member in the singleton class itself?

Pete

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

Back to comp.lang.java.gui | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Singletons and Swing "Jason Cavett" <jason.cavett@THRWHITE.remove-dii-this> - 2011-04-27 15:43 +0000
  Re: Singletons and Swing "Peter Duniho" <peter.duniho@THRWHITE.remove-dii-this> - 2011-04-27 15:43 +0000
    Re: Singletons and Swing "Jason Cavett" <jason.cavett@THRWHITE.remove-dii-this> - 2011-04-27 15:43 +0000
      Re: Singletons and Swing "Peter Duniho" <peter.duniho@THRWHITE.remove-dii-this> - 2011-04-27 15:43 +0000
      Re: Singletons and Swing "tar" <tar@THRWHITE.remove-dii-this> - 2011-04-27 15:43 +0000
  Re: Singletons and Swing "Daniel Pitts" <daniel.pitts@THRWHITE.remove-dii-this> - 2011-04-27 15:43 +0000
    Re: Singletons and Swing "Jason Cavett" <jason.cavett@THRWHITE.remove-dii-this> - 2011-04-27 15:43 +0000

csiph-web