Lesson: EditMode Support for Tooltips

Class EditMode is a ViewMode implementation that provides support for presenting tooltips for both nodes and edges. You can enable tooltip presentation using showNodeTips(true) for nodes and showEdgeTips(true) for edges.

By default, the text that is displayed when tooltips are enabled is that of the first node label, respectively the first edge label.

Figure 1.1. Default tooltip presentation by class EditMode

Default tooltip presentation by class EditMode

Related Resources

You will find related information in the yFiles for Java Developer's Guide:

In the yFiles for Java API:

Customizing Tooltips for Graph Elements

You can easily customize the tooltip text that is displayed for nodes and edges by subclassing EditMode and overriding the getNodeTip and getEdgeTip method, respectively. Figure 1.2, “Custom tooltip text” shows a customized node tooltip.

Figure 1.2. Custom tooltip text

Custom tooltip text

You can incorporate the code to create this presentation into the constructor of the simple graph editor application from the Creating a Simple Graph Editor trail, for example. The SimpleGraphEditor2Tooltips application already uses this code.

Example 1.1. Customizing the tooltip text for nodes using EditMode

editMode = new EditMode() {
  protected String getNodeTip(Node node) {
    Graph2D graph = (Graph2D)node.getGraph();
    return
      "<html>width x height: <b>" +
      graph.getWidth(node) + "</b> x <b>" + graph.getHeight(node) +
      "</b></html>";
  }
};

Related Resources

You will find related information in the yFiles for Java API: