1

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

Hafthor94
  • 11
  • 1

1 Answers1

2

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).

Fizz Areh
  • 87
  • 7
  • 1
    Please don't post only code as answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes. – Mark Rotteveel Jul 31 '22 at 15:57