How to turn off the edge labels in JGraphX?

422 Views Asked by At

I am trying to create a JGraphXAdapter which receives a directed graph as a constructor argument and applied a mxHierarchicalLayout to it. Then, I use mxCellRenderer to create a BufferedImage and write the visualization to a png file.

The problem is that I do not want the edge labels to be visible. I tried (incorrectly) using this command, but it turns off all the labels.

JGraphXAdapter<String, DefaultEdge> graphAdapter = new JGraphXAdapter<>(directedGraph);
graphAdapter.setLabelsVisible(false);

Is there any way to just turn off the edge labels, but not the vertex labels? Thanks

1

There are 1 best solutions below

1
Fizz Areh On

graphAdapter.getEdgeToCellMap().forEach((edge, cell) -> cell.setValue(null));

Edit: there is not much to comment there... "cells" in JGraphX terminology are objects representing visuals of both edges and vertices. So, if you want to change how one specific element is drawn, you should first find its cell through edge->cell or vertex->cell map.

Cell's "value" is its reference to a represented object. Strings that you see on vertices and edges after JGraphX renders everything are basically cell.value == null ? "" : cell.value.toString() (might look a bit different in the source code).