"Moth" <no@email.here> wrote in message news:<Se******************@news-server.bigpond.net.au>...
I have a PlotPanel class that extends JPanel which I have used previously to
display charts in swing guis. I now want to display a graph in a jsp page
so I was going to generate the graph and then save it to a jpeg and then
display it in the page.
Is there anyway to create an Image from a JPanel without actually displaying
it in a JFrame first? Can anyone suggest a better way to create a chart
image for servlet/jsp?
If the plotted chart, not the JPanel component itself, does matter,
draw(or plot) the chart into a BufferedImage and write it to your .jpg
or .png file. You can get the Graphics/Graphics2D object for drawing
from BufferedImage#createGraphics() method. If you reuse your
PlotPanel#paint() method, developing time could be an instant.
Unfortunately it seems we still don't have convenient APIs for
capturing Java GUI component as an Image and for storing them onto
standard image files.