Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #3157
| From | "Peter Duniho" <peter.duniho@THRWHITE.remove-dii-this> |
|---|---|
| Subject | Re: Singletons and Swing |
| Message-ID | <op.t6i95v1c8jd0ej@petes-computer.local> (permalink) |
| Newsgroups | comp.lang.java.gui |
| References | <0a12ac8a-5aff-411b-8934-f855022e5466@e10g2000prf.googlegroups.com> |
| Date | 2011-04-27 15:43 +0000 |
| Organization | TDS.net |
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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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