1 Reply Latest reply on Jun 14, 2012 9:22 AM by gimbal2

    java 2d image capturing without displaying the jcomponent

      My application has a java JComponent where some strings and lines are drawn using the drawString(theStr, xPos, yPos) and drawLine(x1, y1, x2, y2) methods in Graphics2D class. I am able to get this using the createImage(width, height) method in the Component class. This is working fine as long as my JComponent is visible. My requirement is to create the image of the JComponent when it is NOT displayed / visible.

      please help me on this issue.
        • 1. Re: java 2d image capturing without displaying the jcomponent
          Hm, a curious requirement.

          What you could try is to manually invoke the paint() method of the component to let it paint itself onto the BufferedImage.
          BufferedImage bi = new BufferedImage(...); // pass the proper dimensions, what you would pass to createImage()
          Graphics g = bi.createGraphics();
          I have no idea if this will be more successful than what you have already tried.
          1 person found this helpful