I have a JPanel that consists of a lot of JLabels. So there is no paint at all, just JLabels with different background colors and such. The JPanel is visible.
How can I convert this JPanel to an image file? The image file would be a picture of the JPanel exactly as it appears on the screen.
(Ideally, the program would create a .png, and save it to the same folder that the program is in or even a different folder chosen by the user.)
Any advice would be appreciated. Thanks!
---- It's Cherie again, unregistered so I couldn't get back into my account to choose stas's answer as the answer. This is why I'm not replying... anyway, thank you for your help. Cherie
Screen Image will choose the best way to create the image.
BufferedImage bi = ScreenImage.createImage(panel);
ScreenImage.writeImage(bi, "panel.png");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With