J
Jason Cavett
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?
Here is how I am creating my InsertMenu singleton. Could this be the
problem? Thanks.
/**
* This method initializes
*
*/
private InsertMenu() {
super("Insert New...");
initialize();
}
/**
* Provides access to the InsertMenu singleton.
*/
private static class InsertMenuHolder {
private static InsertMenu menu = new InsertMenu();
}
/**
* Provides access to the InsertMenu singleton from outside the
InsertMenu.
*
* @return the insert menu
*/
public static InsertMenu getInstance() {
return InsertMenuHolder.menu;
}
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?
Here is how I am creating my InsertMenu singleton. Could this be the
problem? Thanks.
/**
* This method initializes
*
*/
private InsertMenu() {
super("Insert New...");
initialize();
}
/**
* Provides access to the InsertMenu singleton.
*/
private static class InsertMenuHolder {
private static InsertMenu menu = new InsertMenu();
}
/**
* Provides access to the InsertMenu singleton from outside the
InsertMenu.
*
* @return the insert menu
*/
public static InsertMenu getInstance() {
return InsertMenuHolder.menu;
}