javagraphjung

JUNG change the color of specific vertex


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?


Solution

  • You can certainly supply a more complex Function than v -> Color.blue if you like; for instance:

    vv.getRenderContext().setVertexFillPaintFunction(
        v -> v.equals(specialNode) ? Color.red : Color.blue);
    

    For more information on specifying Functions (using lambda expressions or not), see https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html.