< Zurück | Inhalt | Weiter >

5.4 Group








Group defines a scenegraph Node that contains a collection of child Nodes. It defines the following child

Node management methods:

void addChild(Node child) java.util.Enumeration getAllChildren() Node getChild(int index)

void insertChild(Node child, int index) void moveTo(BranchGroup branchGroup) int numChildren()

void removeChild(int index)

void setChild(Node child, int index)

These methods essentially delegate, in obvious ways, to the internal collection that manages the child Nodes within the Group. Table 5.2 shows the capabilities defined by Group.

Table 5.2 Capabilities defined by Group

Capability bit



Allows child Nodes to be added to the Group


Allows reading of child Nodes (e.g., getChild method)


Allows writing of child Nodes (e.g., setChild method)


Allows reading of collision Bounds


Allows writing of collision Bounds

Group is an important base class for the Java 3D Node management classes, and it can also be instantiated in its own right. For increased flexibility, however, I recommend BranchGroup Nodes because they can be dynamically added or removed from the scenegraph. The classes derived from Group are shown in table 5.3.

Table 5.3 Classes derived from Group




A dynamically insertable and removable Group


A Group that renders its children in a defined order, irrespective of location


A geometric Group used to manage geometry in the utils package


A Group that can be reused across the scenegraph and can be attached to multiple parents


A Group that can conditionally display its child Nodes


A Group that has an associated geometric transformation containing rotation, translation, and scale information that is applied to its child Nodes before rendering

Note that an instance of any of the Group−derived classes, including SharedGroup, can only be added to a single location within the scenegraph. Attempting to add a scenegraph node to a scenegraph that already has an assigned parent (i.e., a node that has already been added to the scenegraph) will result in a run−time exception. I discuss reusing scenegraph branches using a SharedGroup and a Link later in this chapter.


5.4.1 Remove a child Node by reference