I have a JMenuItem callback that calls a new instance of a derived class of JFrame.
Whenever the JMenuItem callback is called, the original popup is not brought back to the front of my main application. Instead, it creates a new instance and a new window popup (so there are two or more of the same derived class).
How do I make it so there is at most one derived class instance at all time?
If there really should never be more than one instance of your derived class, you can make it a Singleton, e.g.
You simply call
MyFrame.getInstance()when you need to get an instance rather than using new, and will get the same one every time (it will be created the first time). e.g.If you’ll be doing this from more than one place, then it would probably make sense to create a further static method in
MyFrameand place the code in there. e.g.Then you can simply call
MyFrame.popUp().