JFreeChart in Eclipse RCP & SWT

To use JFreeChart in a Eclipse RCP project or simply embed in an SWT composite, you have two applicable choices: org.jfree.experimental.chart.swt.ChartComposite from JFreeChart SWT experimental project, which I can not say works seamless.

SWT_AWT bridge, hmm, not perfect but plays its role better.

Composite container = new Composite(parent, SWT.EMBEDDED)
java.awt.Frame chartFrame = SWT_AWT.new_Frame(container)
SwingUtilities.invokeLater(new Runnable() {
     public void run() {
          ChartPanel chartPanel = new ChartPanel(chart, true);
          chartFrame.add(chartPanel);
     }
})

That’s it!

Migrated from old blog: jfreechart-in-eclipse-rcp-swt

Tweet