The solution for anyone who has the same question:
FontMetrics fm = vv.getFontMetrics(vv.getFont());
int width = fm.stringWidth(i);
vv is the VisualizationViewer
Question
I started working with java jung. I got a few problems due to the lack of good tutorials. I think i need a few timeto get into it.
Well my problem is:
I created a network with vertices (circles) which are labeled with text (strings). my problem is to fit the size (width) of the circles to the string.
I wanted to set it dynamically but dont know how to iterate through the vertices.
Solution
The solution for anyone who has the same question:
FontMetrics fm = vv.getFontMetrics(vv.getFont());
int width = fm.stringWidth(i);
vv is the VisualizationViewer
OTHER TIPS
For vv
, a VizualizationViewer
, you can add a VertexShapeTransformer
.
The following Scala code is easily translatable into Java.
vv.getRenderContext().setVertexShapeTransformer(
new org.apache.commons.collections15.Transformer[String,java.awt.Shape]() {
def transform(label: String): java.awt.Shape = {
val width = label.length * 10.0
val circle = new java.awt.geom.Ellipse2D.Double(-(width/2), -12.5, width, 25);
circle // return circle
}
})