Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How can I change my TopComponent to not be a singleton?

singleton topcomponent
0
Posted

How can I change my TopComponent to not be a singleton?

0

The “New Window Component” wizard in the NetBeans IDE generates a singleton TopComponent. That’s fine for some uses, but often you will want to create multiple instances of your TopComponent. The good news is that you won’t have to write any code — you’ll just have to delete some of the code that was generated for you. In your TopComponent’s .java source file: • Delete the static instance variable, which ought to be declared a few lines above the constructor. • Make constructor public • Delete the getDefault() method (typically somewhere around the middle of the file) • Delete the findInstance() method (which typically follows the getDefault() method) • Delete the writeReplace() method (typically towards the end of the file) • Delete the ResolvableHelper inner class (typically towards the end of the file) • Only singleton TopComponents can have a persistence mode of PERSISTENCE_ALWAYS, so you must locate the getPersistenceType method and change its return value to either TopComponent.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123