This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
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!
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.