title: Jung coloring vertex with value
body: <p>I'm stuck at the moment with the Java library Jung.</p>
  
  <p>I display vertices and edges, only I can not find any functions for vertex coloring that I need with the value of the vertices and not with the mouse.</p>
  
  <pre><code>import edu.uci.ics.jung.algorithms.layout.FRLayout;
  import edu.uci.ics.jung.algorithms.layout.Layout;
  import edu.uci.ics.jung.graph.Graph;
  import edu.uci.ics.jung.visualization.BasicVisualizationServer;
  import edu.uci.ics.jung.visualization.decorators.PickableVertexPaintTransformer;
  import edu.uci.ics.jung.visualization.decorators.ToStringLabeller;
  import edu.uci.ics.jung.visualization.renderers.DefaultVertexLabelRenderer;
  import edu.uci.ics.jung.visualization.renderers.Renderer.VertexLabel.Position;
  
  import java.awt.BasicStroke;
  import java.awt.Color;
  import java.awt.Dimension;
  import javax.swing.JFrame;
  
  import org.apache.commons.collections15.Transformer;
  import org.apache.commons.collections15.functors.ConstantTransformer;
  
  public class Design {
       public Graph&lt;String, Integer&gt; g;
      public Design() {     
  
           this.g = ProjectTools.readNet("SmallTown.net");
      }
  
      public static &lt;Paint&gt; void main(String[] args) {
          Design sgv = new Design(); 
          Layout&lt;Integer, String&gt; layout = new FRLayout(sgv.g);
          layout.setSize(new Dimension(800,800));  
          BasicVisualizationServer&lt;Integer, String&gt; vv =
              new BasicVisualizationServer&lt;Integer, String&gt;(layout);
  
          Transformer&lt;Integer,Paint&gt; vertexPaint = new Transformer&lt;Integer,Paint&gt;() {
              public Paint transform(Integer i) {
                  return (Paint) Color.GREEN;
              }
          };  
  
          vv.setPreferredSize(new Dimension(850,850));
          vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.green));
          vv.getRenderContext().setEdgeDrawPaintTransformer(new ConstantTransformer(Color.white));
          vv.getRenderContext().setEdgeStrokeTransformer(new ConstantTransformer(new BasicStroke(2.5f)));
  
          vv.getRenderContext().setVertexFillPaintTransformer((Transformer&lt;Integer, java.awt.Paint&gt;) vertexPaint);
          vv.getRenderContext().setVertexFillPaintTransformer(new PickableVertexPaintTransformer&lt;Integer&gt;(vv.getPickedVertexState(), Color.green, Color.yellow));
  
          vv.setBackground(Color.gray);
          vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller&lt;Integer&gt;());
          vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
  
  
          JFrame frame = new JFrame("Projet Algo");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.getContentPane().add(vv); 
          frame.pack();
          frame.setVisible(true);       
      }
  }
  </code></pre>
  
  <p>My rendering :
  <img src="https://i.stack.imgur.com/Eco9m.jpg" alt="Vertices and edges"></p>