I\'ve been using JUNG to visualize some simple graphs, and I\'d like to write several of them to a PNG file. Unfortunately, the images often appear to render before the graph is
We usually want to save the state of a manipulated graph. We zoom and position the components the way we like and then we make a picture of the container. This can be achieved like this:
Pass the JPanel inside your JScrollPane, or any Component that hosts your JUNG2 graph to ScreenImage.createImage in order to create an image.
private void writeToImageFile(String imageFileName) {
BufferedImage bufImage = ScreenImage.createImage((JComponent) jPanel1);
try {
File outFile = new File(imageFileName);
ImageIO.write(bufImage, "png", outFile);
System.out.println("wrote image to " + imageFileName);
} catch (Exception e) {
System.out.println("writeToImageFile(): " + e.getMessage());
}
}
Read also other topics of the above mentioned blog :-)