JFreeChart in Eclipse RCP & SWT
01 Sep 2010 java eclipse swtTo 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.
- Create a container composite with
SWT.EMBEDED
style (required forSWT_AWT
).
Composite container = new Composite(parent, SWT.EMBEDDED)
- Create new AWT Frame using container.
java.awt.Frame chartFrame = SWT_AWT.new_Frame(container)
- Create a JFreeChart
ChartPanel
and append on chartFrame. (This should be done in AWT Event Thread)
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