To force a node to the first level, you can specify:
layout.setSpecNodeLevelIndex(node, 0);
However, you cannot specify a level index for the last
level because it is unknown at the beginning of layout how many levels
are created. It is unwise to specify:
layout.setSpecNodeLevelIndex(node, Number.MAX_VALUE);
because it creates many empty levels between the levels
used and the last one. Even though these empty levels are removed
in postprocessing steps, it influences the speed and quality of the
layout. (In fact, the algorithm runs out of memory if you set the
specified level index unreasonably high.)
By using constraints you can achieve the same effect
more efficiently.
To force a node to the first level:
Call:
layout.addConstraint(new ibm_ilog.graphlayout.hierarchical.HierarchicalExtremityConstraint(node, ibm_ilog.graphlayout.hierarchical.HierarchicalLayout.NORTH));
To force a node to the last level:
Call:
layout.addConstraint( new ibm_ilog.graphlayout.hierarchical.HierarchicalExtremityConstraint(node, ibm_ilog.graphlayout.hierarchical.HierarchicalLayout.SOUTH));
With compass directions as a convenient reference (see Port sides parameter (HL)), the first
level indicates the north pole and the last level indicates the south
pole. You can also specify extremity constraints for the east and
west sides:
layout.addConstraint( new ibm_ilog.graphlayout.hierarchical.HierarchicalExtremityConstraint(node1, ibm_ilog.graphlayout.hierarchical.HierarchicalLayout.EAST)); layout.addConstraint( new ibm_ilog.graphlayout.hierarchical.HierarchicalExtremityConstraint(node2, ibm_ilog.graphlayout.hierarchical.HierarchicalLayout.WEST));
The west extremity constraint forces the node to the
lowest position index within its level, and the east extremity constraint
forces the node to the highest position index within its level. The
position indexes specify the relative position within the level. For
instance, a node with west extremity constraint is the leftmost node
within its level, if the flow direction is towards the bottom. However,
it does not affect other levels; there can be a node in another level
that is still placed farther to the left.
The following figure illustrates some extremity constraints.

Sketch of Extremity Constraints