By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,635 Members | 2,188 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,635 IT Pros & Developers. It's quick & easy.

Create java image from Jpanel without displaying

P: n/a
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?
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
RChart includes a servlet which does not needs to display any panel:

http://www.java4less.com/charts_e.htm
"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?

Jul 17 '05 #2

P: n/a
"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.
Jul 17 '05 #3

P: n/a
"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?


I've not tried this personally, but in theory it should work. Create an
Image of the appropriate size to hold the JPanel, get a Graphics object
from it - then call the JPanel's paint() method directly with your own
Graphics object. The component *should* paint itself, and its children,
into your Image in exactly the same way as it does to screen.
-FISH- ><>
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.