I'm having an issue with painting a ChartPanel. This is using the JFreeChart 1.0.19 distribution.
Basically, there is a null pointer exception here....
Code: Select all
GraphicsConfiguration gc = g2.getDeviceConfiguration();
this.chartBuffer = gc.createCompatibleImage(this.chartBufferWidth, this.chartBufferHeight,
Transparency.TRANSLUCENT);
The problem seems to be that the Graphics2D object is returning a null device configuration, so the paint operation fails.
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at org.jfree.chart.ChartPanel.paintComponent(ChartPanel.java:1601)
at javax.swing.JComponent.printComponent(JComponent.java:1218)
....
Can anyone discuss under what circumstances this would happen and how I might go about fixing it? Is there some method I can call to make sure this will work? Is it perhaps actually related to the state of the Graphics object that is being passed into this method rather than any bug or issue with ChartPanel?
If more details are needed about how this is being called then let me know. There is a separate external library I am using for actually saving the chart graphics, which I think is trying to paint the panel into its own graphics object and then persist it. I'm sure this has something to do with the problem I'm seeing. Perhaps there is a suggestion about how to go about doing this without causing these kinds of bugs, e.g. successfully exporting the ChartPanel graphics via this paint operation. (For technical reasons, it is difficult for me to instead use the built-in JFreeChart save command but I could also take a look at how that works too.)
By the way, rendering the chart graphics into my Swing application's components is working fine without any major issues.
Thanks.
--Jeremy