How can I draw a tree hierarchy using a JUNG?

I am new to JUNG . I tried drawing a tree graph using TreeLayout, but the tree never appears as a real tree. Each time the tree looks different. How can I make a tree look like an ordinary tree with a root on top and the other nodes coming down from it?

+7
java graph layout tree jung
source share
1 answer

You should initialize the TreeLayout after adding vertices to the chart, I tried this and it worked for me.

You should do something like the following: (note that this is the 1 year old code that I had, you may find that it is a bit outdated)

 Layout<GraphVertex, GraphEdge> layout; //create a layout layout = new TreeLayout<GraphVertex, GraphEdge>((Forest<GraphVertex, GraphEdge>) g); // initialize your layout using the graph you created, which has to be of type forest vv.setGraphLayout(layout); // set the layout of the visualization viewer you are using to be the layout you just created (the tree layout) 

GraphVertex Is a class that represents the vertex in a graph, GraphEdge represents edges on your graph.

+5
source share

All Articles