JUNG change color of an spceific

doktordoom

Mitglied
Hi,
at the moment, I'm trying to change the color of a specific vertex in JUNG. I know i can use the following function to change the color of all nodes. Is it possible to substitute v from the following line with a specific node.

vv.getRenderContext().setVertexFillPaintFunction(v -> Color.blue);

Or should i use transformer classes?

I checked out the jungrapht-visualization-master.

An example would be great. Thx!
 
setVertexFillPaintFunction accepts Function as parameter. Therefore you can pass any logic.
e.g.:

Java:
   vv.getRenderContext().setVertexFillPaintFunction(v -> {
       if (v.id == 1) {
           return Color.red; 
       }
       return Color.yellow;
   });
 
Hi @looparda,
thanks you approach work well. One more question. How can i change the color of an list of specific vertexes ?
The following approach doesn't work.

Java:
      vv.getRenderContext().setVertexFillPaintFunction(v -> {
                if (v.equals("B0") && (v.equals("Z0") && (v.equals("V0")))) {
                  return Color.yellow;
                }
                return Color.green;
              }
      );
 
You might want to use || instead.
To be more dynamic you can use List#contains to do something like this:
Java:
List<MyNode> highlightNodes = new ArrayList<>();
highlightNodes.add(v1);
highlightNodes.add(v2);
highlightNodes.add(v3);
vv.getRenderContext().setVertexFillPaintFunction(v -> highlightNodes.contains(v) ? Color.yellow : Color.green);
 

Neue Themen


Zurück
Oben