Domanda

Sono nuovo di JUNG . Ho cercato di disegnare un grafico di un albero con il TreeLayout ma l'albero non esce mai come un vero albero. Ogni volta che l'albero un aspetto diverso. Come posso fare il look albero come un albero normale con la radice in alto e il resto dei nodi discendente da esso?

È stato utile?

Soluzione

È necessario inizializzare la TreeLayout dopo aver aggiunto i vertici al grafico, ho provato e ha funzionato per me.

Devi fare qualcosa di simile a quanto segue: (si prega di notare che questo è un vecchio codice 1 anno che ho avuto, si potrebbe trovare ad essere un po 'datata)

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 è la classe che rappresenta un vertice nel grafico, GraphEdge rappresenta i bordi nel grafico.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top