I have a couple of charting classes that I want to be able to include in PDF reports created by my program. The classes all extend JComponent. My problem is that when I convert the Components to images, I always get a black image.
I'm using this code that I pieced together from various places:
Now, I've tried adding the charting component to a JPanel and then trying to print that component onto the image, and I am able to see the JPanel's default background color, but no sign of the charting component.
I've also tried using a few different variations of Buffered Image types (other than TYPE_INT_RGB), but felt I was getting nowhere. Is there something here I'm missing?
(And PS: What's the difference between print() and paint() for a Component?)
Michael, the code on that page (ScreenImage.java) is very handy; I'm saving that one.
Unforunately, it still didn't work for these charting components. I ended up browsing through the code (which has been put through an obfuscator) and finding a render(Graphics) method which did the trick. How odd that even though the charts extend JComponent and show up in a program fine, they refuse to draw onto an image, something other JComponents did fine.
Thanks so much for the prompt reply and useful link, however!