Getting image from JGoView



I have a JGoView component and which is present in a JFrame.
I have a requirement for converting the JGoView into an image. I am using to convert as image using following code
JgoView view = getJGoView();

Dimension canvassize = view.getCanvas().getSize();

BufferedImage bi = new BufferedImage(canvassize.width, canvassize.height, BufferedImage.TYPE_INT_ARGB);
But the image which is coming has scrollbars in it (basically the image contains the current view of the JFrame ). If i increase the JFrame size then image will contain more area. I am not getting the full image of JGoView. When i print, i get the full image of JGoView component. Can you please let me know how to get the image of full area JGoView component.


Take a look at the following topic in this forum (topic “Export Image from JGoView”:


Thanks for the reply. I am using the following code to save the JGoView as an image file

            JGoView view = getJgoView();

<span =“Apple-tab-span” style=“white-space:pre”> Dimension canvassize = view.getDocumentSize();
<span =“Apple-tab-span” style=“white-space:pre”> final int _width = canvassize.width;
<span =“Apple-tab-span” style=“white-space:pre”> final int _height = canvassize.height;
<span =“Apple-tab-span” style=“white-space:pre”> view.setSize(_width, _height);
<span =“Apple-tab-span” style=“white-space:pre”>
<span =“Apple-tab-span” style=“white-space:pre”> view.getCanvas().setSize(_width, _height);

<span =“Apple-tab-span” style=“white-space:pre”> BufferedImage bi = new BufferedImage(_width, _height, BufferedImage.TYPE_INT_ARGB);
<span =“Apple-tab-span” style=“white-space:pre”> Graphics2D g2 = (Graphics2D)bi.getGraphics();
<span =“Apple-tab-span” style=“white-space:pre”> g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
<span =“Apple-tab-span” style=“white-space:pre”> g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
<span =“Apple-tab-span” style=“white-space:pre”>
<span =“Apple-tab-span” style=“white-space:pre”> view.getCanvas().paint(bi.createGraphics());

<span =“Apple-tab-span” style=“white-space:pre”> ImageIO.write(bi, “png”, outputFile);

I have the following problems

  1. When i add the JGoView object in a container e,g JFrame and then do frame.pack() and then frame.setVisible(true), the image comes out perfectly

But when i dont put JGoView in the JFrame, after building JGoView object, directly try to convert it into image, my image is not layout properly.

I tried to print out the JGoView object but in the print out also, we i use JFrame to put the JGoView and do frame.pack() and frame.setVisible(true), printout come properly otherwise when i dont use any frame, and just do print out using JGoView object, printout image is not layout properly (Shape and size are not coming properly).

So, I just wanted to know, to layout the JGoView component properly, do we need to put into some container? Or do we have any other direct call to layout if we are not putting JGoView obj into any container._


No, you shouldn’t need any special container. In fact, if you replace the first line above with:

JGoView view = new JGoView();

The JGoView is clearly not contained in any special container and it seems to work fine.