Changing the Drawing Order of Nodes and Edges |
| Applies to: yFiles for Java 2.9, 2.8, 2.7, 2.6, 2.5, 2.4, 2.3, 2.2, 2.1, 2.0 |
Type: Tips & Tricks
Categories this article belongs to:
| yFiles for Java | > yFiles Viewer | > Displaying and Editing Graphs | > View Implementations |
Drawing nodes on top of all edges and vice versa.
Normally, the edges of a graph that is displayed in a view (an instance of type Graph2DView
) are drawn on top of all nodes.
This behavior can be changed to draw nodes on top of all edges using method DefaultGraph2DRenderer.setDrawEdgesFirst(boolean)
.
The following sample code demonstrates how to do it.
What the sample code does:
-
Creates a new instance of class DefaultGraph2DRenderer
,
- sets the desired behavior (in this case, to draw edges first, i.e., nodes on top of all edges), and
- registers the newly created DefaultGraph2DRenderer with the view.
void configureGlobalDrawingSequence(Graph2DView view, boolean drawNodesOnTopOfEdges) { DefaultGraph2DRenderer dgr = new DefaultGraph2DRenderer(); // Drawing edges first implies that nodes are drawn last, i.e., on top of the edges. dgr.setDrawEdgesFirst(drawNodesOnTopOfEdges); // Register the freshly configured DefaultGraph2DRenderer with the given view. view.setGraph2DRenderer(dgr); } |
| Keywords: | drawing - sequence - edge - edges - node - nodes - above - below - front - back |


