This reply is correction to an old message which I tried to use now and found incorrect.
In the StudentsWithUI.java tutorial of the manual, I wanted to color the edges according to attraction/repulsion.
The advice found here was to subclass SimpleEdgePortrayal2D, and override its draw() method.
In that method, one was supposed to use graphics.setColor() and then call super.draw() with this graphics.
But this did not change the edge color. What worked was to change toPaint and fromPaint before calling super.draw().