I have a class that extends a panel on which I have drawn some lines with
((Graphics2D) getGraphics).drawLine(x, y, x, y);
The lines are drawn correctly on the panel but when I run the following code to save an image (which I found on the internet) I save the panel without the lines
/**
* Save the Panel as image with the name and the type in parameters
*
* @param name name of the file
* @param type type of the file
*/
public void saveImage(String name,String type) {
BufferedImage image = new BufferedImage(getWidth(),getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = image.createGraphics();
paint(g2);
try{
ImageIO.write(image, type, new File(name+"."+type));
} catch (Exception e) {
e.printStackTrace();
}
}