I use JUNG to visualize my graph / network. Now i want to save the graph (as seen in the VisualizationViewer) in a image file. I use the paint() / paintAll() function of the VisualizationViewer (who extend JPanel). But with this function, only the part who is actually shown in the VisualizationViewer (for example after zooming in) is in the image. I want to draw all Vertexes and Edges. Is there a way to draw all Elements?
JUNG: Saving graph into image file
1.7k Views Asked by Thargor At
2
There are 2 best solutions below
1

I don't know anything about JUNG, but it is just extends a JPanel to do the painting then you should be able to use the Screen Image class to create an image of any component.
I found a solution using the freeHEP library and JUNG's
VisualizationImageServer
:When called, this will open an export dialog to the user, where directory and filetype can be selected.
In this snippet, ExportDialog is
org.freehep.graphicsbase.util.export.ExportDialog
, which you would have to somehow get to your build path, in my case using maven by addingfreehep-graphicsio
to my pom file.The field
this.visViewer
contains your regularVisualizationViewer
instance, that you would also use for displaying your graph.The method
setUpAppearance(vis);
performs the same setup that I do on theVisualizationViewer
instance for displaying purposes. Here's an example, the details will probably vary for you:As a last step you need to figure out when
doSaveAs
should be called. For instance you could add a Button on the UI for that.