brunomnsilva / JavaFXSmartGraph

Generic (Java FX) Graph Visualization Library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: Programmatically changing node colors

GaudiestTooth17 opened this issue · comments

I've never worked with CSS before, so maybe this is obvious, but is there any way to change the color of nodes in the code? I know that you can change the styles nodes used based on preconfigured CSS entries, but I'd like to be able to have nodes slowly fade from one color to another to show gradual changes in "attitude" of nodes.

Hi @GaudiestTooth17 ,

You already have an example of that in the main program:

        /*
        After creating, you can change the styling of some element.
        This can be done at any time afterwards.
        */
        if (g.numVertices() > 0) {
            graphView.getStylableVertex("A").setStyle("-fx-fill: gold; -fx-stroke: brown;");
        }

This way you can overwrite any existing css property of a given node/edge.

For you to "animate" a gradient change, that will entail some kind of thread in which you progressively change the color of it.