Question

I'm new to JUNG. I have created nodes in a Graph. Now when ever I run the program I get nodes with different location. How can I load the nodes I created in same location everytime?

Was it helpful?

Solution

There are a few ways of going about this.

(1) Get the nodes where you want them, and then save the positions for later use. For example, you can use PersistentLayoutImpl (if you want to serialize the entire graph), or store some kind of map from vertex identifier to layout position.

(2) Specify a consistent random seed when you create the layout. You'll do this via the initializer; see AbstractLayout for details.. (Not all layouts expose this capability, you might need to hack one to provide your own initializer.)

(3) Use a layout that doesn't have any random elements.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top