Hi all the code i am using is
/**
* Create a BufferedImage for given component.
* Opens a Save dialog box, takes the location to save.
* All or part of the component can be captured to an image.
*@param component Swing component to create image from
* */
private void saveDtv(Component component,
String fileName)
{
if (fileName != null)
{
try{
File name=new File(fileName);
BufferedImage image =new BufferedImage( component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics2D g = image.createGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
component.paint(g);
g.dispose();
ImageIO.write(image,"png",name);
}catch(Exception ex)
{
Log.gLog().debug("In createImage() Error while image capture:",ex);
JOptionPane.showMessageDialog(MainFrame.getMainFrame(),ex,"Error",JOptionPane.ERROR_MESSAGE);
((JDialog)component).dispose();
}
}
((JDialog)component).dispose();
}