Quick NetBeans RCP Tip: How to reuse an already open TopComponent instead of creating a new one.

Well, NetBeans RCP is a flagship product of NetBeans Project which the famous NetBeans IDE is based on it. To reuse an already opened TopComponent in an RCP application we can use a code similar to following listing, Assume that the TopComponent name is ContractorInfoTopComponent and we want to reuse the already opened tab instead of creating a new one.


Set tset = WindowManager.getDefault().getRegistry().getOpened();

            for (TopComponent t : tset) {
                  if (t instanceof ContractorInfoTopComponent) {
                    ContractorInfoTopComponent citc = (ContractorInfoTopComponent) t;
        	    citc.requestActive();
                }
            }

NetBeans RCP is the answer to creating complex and large scale swing applications in a modular way.