Creating Node Subclasses

Nodes are useful for many things beyond just representing files. If you just need a placeholder Node, you do not need a subclass - just instantiate an AbstractNode - despite its name, AbstractNode is not an abstract class. For example:

AbstractNode nue = new AbstractNode (Children.LEAF);
nue.setDisplayName ("Please wait...");
nue.setIcon (Utilities.loadImage ("path/in/jar/to/image.gif"));
return nue;

If you are creating Nodes, you will typically deal with one of four things

  • AbstractNode - create a Node which represents anything you want - you will implement all its logic, provide children, etc. Typically most logic goes in the Children object.
  • BeanNode - a very convenient Node subclass, which can represent any JavaBean as a Node and expose its bean properties as Property objects that can be edited on the property sheet
  • FilterNode - a Node subclass that proxies another Node. You can subclass this to take an existing Node (possibly representing a file on disk or in the system filesystem and keep most of its attributes, but provide different actions or display name or icons or properties
  • DataNode - a Node subclass specific to editing files. If you are writing a module that adds support for a new file type (such as .svg files), you will write a DataNode subclass to give files of that type icons, display names, and possibly provide access to the file's content

Note that if you just want to write context sensitive code, not provide your own Nodes, you may be able to do it without a dependency on the Nodes API, using Utilities.actionsGlobalContext().

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo