Re: how to reference to other topcomponent

Peter Blemel <[email protected]> Fri, 7 Oct 2016 21:58:22 +0000
Newsgroups gmane.comp.java.netbeans.devel
Message-ID <SN1PR02MB1374120E515E455E91A5C97FB0C60@SN1PR02MB1374.namprd02.prod.outlook.com>
Hi Peter,


This is not a good design choice.   The SymbolWindowTopComponent should be listening for changes and updating itself, instead of making a member variable public and allowing other classes to update it.   For a modular design it is best to use something called a 'lookup'.


https://platform.netbeans.org/tutorials/nbm-selection-1.html

NetBeans Selection Management Tutorial for NetBeans Platform<https://platform.netbeans.org/tutorials/nbm-selection-1.html>
platform.netbeans.org
NetBeans Selection Management Tutorial I-Using a TopComponent's Lookup. This tutorial covers how to write components that provide a "selected object" and how ...


Regards,

Peter




________________________________
From: mcheung63 <[email protected]>
Sent: Friday, October 7, 2016 2:17 AM
To: [email protected]
Subject: [nbdev] how to reference to other topcomponent

now i got a super simple solution, create a Global class:

public class Global {
        public static SymbolWindowTopComponent window;
}

then self register the window in the static variable:

Global.window = this;

finally in other window, i can:

Global.window.jLabel1.setText("peter");

BUT IS IT NORMAL? ANY HIDDEN DISADVANTAGE FOR THIS METHOD?

thanks
from Peter