【技术心得】在Eclipse RCP平台中使用Java AWT的部件
在Eclipse RCP中使用Java AWT的部件一般情况下很少会用到。特殊情况下使用也是有必要的,例如我在RCP程序中用JFreeChart显示图表的时候就会用到这种功能。示例代码如下:
public void createPartControl(Composite parent)
{
Composite awtComposite = new Composite(parent, SWT.EMBEDDED SWT.NO_BACKGROUND);
// a M$ Windows specific property that prevents some components from erasing
// their background, thus reducing window flickering (in theory :) )
try
{
System.setProperty("sun.awt.noerasebackground", "true");
} catch(NoSuchMethodError ignore){// Ignore this error}
// SWT-AWT Bridge
awtFrame = SWT_AWT.new_Frame(awtComposite);
awtPanel = new Panel(new BorderLayout())
{
public void update(Graphics g) { paint(g); } };
// Generate the Chart. Add the chart to the panel
chart = new JFreechartFactory...blabla
cp = new ChartPanel(chart);
awtFrame.add(cp);
}
以上代码片断在我的示例程序中运行成功。
没有评论:
发表评论