I tried create a Java JGraphT visualization with Weight, for example:
Now I want to change the edge label (ex: (a:b) to its edge weight (ex: 2). I tried to search in Javadoc but didn't see anything. Please help me thank you!
Those edge labels came from the toString
method of the edge object. Therefore you may create your own edge class and override the toString
method in such a way that it yields the edge weight.
You may create your custom edge like this:
class MyWeightedEdge extends DefaultWeightedEdge {
@Override
public String toString() {
return Double.toString(getWeight());
}
}
And then create your graph like this which will make the graph create edges as instances of MyDefaultEdge
and therefore display just edge weight in the visualization:
SimpleWeightedGraph<String,MyWeightedEdge> graph
= new SimpleWeightedGraph<String,MyWeightedEdge>(MyWeightedEdge.class);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With