how to force a redraw event from JFreeChartPanel ?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Mudit Wahal

how to force a redraw event from JFreeChartPanel ?

Post by Mudit Wahal » Mon Jul 15, 2002 8:48 pm

David and all,

I've extended JFreeChartPanel to draw trend lines etc. I've installed a mouse handler which keeps tracks of mouse pressed/dragged/released and uses that information to draw trend lines in the panel. I've also added few classes and extended XYPlot to plot labels on any given x,y point. The lines are draw in the paintComponent() of the JFreeChartPanel. Each lines I draw has label associated with it.

The labels are plotted in the XYPlot->draw() method. Since the labels are not drawn in the paintComponent method, they are not displayed the instance lines are drawn. Is there anyway to trigger the draw method of xyplot from the JFreeChartPanel so that the labels are drawn the same instance ? Similarily, when I move the lines, the labels should also move at the same time. Since no draw event is posted labels, remain at their old location for sometime, till i click in the chart or move it force a draw.

Thanks

Mudit

David Gilbert

Re: how to force a redraw event from JFreeChartPanel ?

Post by David Gilbert » Tue Jul 16, 2002 9:24 am

There are various paths through the paintComponent method, all of which should call the chart.draw(...) method once and only once. This in turn calls the plot.draw(...) method. Perhaps with your modifications the chart.draw(...) method is being skipped?

Regards,

DG.

Mudit Wahal

Re: how to force a redraw event from JFreeChartPanel ?

Post by Mudit Wahal » Tue Jul 16, 2002 6:26 pm

David,

I've extended JFreeChartPanel->paintComponent and the XYPlot->draw methods. I have not extended Chart->draw method.

I looked at the code for JFreeChart and fireChartChanged() will trigger a redraw event. Unfortunately its a protected method and not available, neither notifyListeners. So, I went roundabout via following call,

JFreeChartPanel jp;

jp.getChart().setTitles(jp.getChart().getTitles());

setTitles calls fireChartChanged event without checking if the titles are same or different (unless it changes in future).

----- my changes to JFreeChartPanel->paintComponent -------
public void paintComponent(Graphics g) {
super.paintComponent(g);
// the trend lines are draw here in the next method
if (mhandler != null)
mhandler.paintComponent(g);

}
-----------------------------------------------------------

I event tried jp.repaint, jp.invalidate, jp.revalidate. Neither of these trigger the draw method of chart.draw or xyplot.draw.

Thanks

Mudit

David Gilbert

Re: how to force a redraw event from JFreeChartPanel ?

Post by David Gilbert » Thu Jul 18, 2002 5:07 pm

Another thing to try, the ChartPanel stores the chart in an offscreen image buffer, to enable fast repaints of the panel when the chart hasn't changed. Some calls to paintComponent will just redraw the old buffer. You can use setRefreshBuffer(true) to force the buffer to be redrawn next time through the paintComponent method.

Regards,

DG.

Mudit Wahal

Re: how to force a redraw event from JFreeChartPanel ?

Post by Mudit Wahal » Thu Jul 18, 2002 6:21 pm

Will try that out !

Thanks

Mudit

Mudit Wahal

Re: how to force a redraw event from JFreeChartPanel ?

Post by Mudit Wahal » Thu Jul 18, 2002 6:24 pm

this works much better !!!!

thanks !!

mudit

Locked