How is it possible to store a JPanel
as a jpeg image the solutions I could search takes a snapshot of the display, this does not capture all the contents of the JPanel
as part of it is hidden. Is there any way of getting the entire image in jpeg.
This solution available here is not working fine at all solution
code I am currently using to take snapshot of JPanel
if (panelx == null) {
jButton3.setText("Generate Diagram");
} else {
jButton3.setText("Generate Diagram");
jTextPane1
.setText(Messages.getString("statement2")); //$NON-NLS-1$
JFrame win = (JFrame) SwingUtilities
.getWindowAncestor(panelx.panelx);
Dimension size = win.getSize();
// BufferedImage image = new BufferedImage(size.width, size.height,
// BufferedImage.TYPE_INT_RGB);
BufferedImage image = (BufferedImage) win.createImage(size.width,
size.height);
Graphics g = image.getGraphics();
win.paint(g);
g.dispose();
try {
ImageIO.write(
image,
Messages.getString("Statement38"), new File(Messages.getString("statement5"))); //$NON-NLS-1$ //$NON-NLS-2$
} catch (IOException e) {
System.out.println("Image cannot be created");
}