fix for minor print dialog bug

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

fix for minor print dialog bug

Post by matt » Fri Feb 01, 2002 2:21 am

hi,
I've noticed a minor bug when printing, if you move the print dialog box around the background doesn't repaint. If anyone else has this problem, I post a quick fix here where I do the printing on a separate thread.

minor changes to JFreeChartPanel-

Modify this method to read:
/**
* Creates a print job for the chart.
*/
public void createChartPrintJob() {
PrintThread thread = new PrintThread(this);
thread.start();
}

Add this class:
/**
* Class that does the printing on a separate thread.
*/
protected class PrintThread extends Thread {
private JFreeChartPanel chartPanel;
public PrintThread(JFreeChartPanel cp) {
super();
chartPanel = cp;
}

public void run() {
PrinterJob pj = PrinterJob.getPrinterJob();
if (pj.printDialog()) {
pj.setPrintable(chartPanel);
try {
pj.print();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

David Gilbert

Re: fix for minor print dialog bug

Post by David Gilbert » Fri Feb 01, 2002 3:39 pm

Hi Matt,

Thanks for the fix. I'll incorporate it into the next version.

Regards,

DG

Locked