我正在使用AWT_SWT框架桥将图形API嵌入到eclipse插件应用程序中。一切正常,但我在移动或滚动框架时面临闪烁/重新绘制问题。我做了很多R& D,尝试了一些解决方案,如System.setProperty("sun.awt.noerasebackground", "true"); or
component.setDoubleBuffered(true);`或使用面板或没有JPanel或使用JComponent,但都不适合我。这是我的代码示例
// main composite
Composite mainComposite = new Composite(GraphicalViewPart._parent, SWT.EMBEDDED | SWT.NO_BACKGROUND);
System.setProperty("sun.awt.noerasebackground", "true");
// System.setProperty("sun.awt.noerasebackground", "true");
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 1;
mainComposite.setLayout(gridLayout);
mainComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
// main frame
awtframe = SWT_AWT.new_Frame(mainComposite);
// panel in frame
/*
java.awt.Panel awtpanel = new java.awt.Panel(new BorderLayout()) {
public void update(java.awt.Graphics g) {
// Do not erase the background
paint(g);
}
};
*/
JComponent component=new JComponent() {
};
component.setDoubleBuffered(true);
awtframe.setLayout(new java.awt.GridLayout());
awtframe.add(component);
请帮我找到解决方法。提前谢谢。
答案 0 :(得分:0)
如月食文章Swing/SWT Integration中的“创建根窗格容器”部分所述,您必须将重量级组件设置为框架的第一个子组件。只能使用JApplet
:
Composite composite = new Composite(parent, SWT.EMBEDDED | SWT.NO_BACKGROUND);
Frame frame = SWT_AWT.new_Frame(composite);
JApplet applet = new JApplet();
applet.add(myComponent); //add your component here
frame.add(applet);
就我而言,此解决方案解决了所有问题,包括调整大小期间的闪烁。
与SWT 3.4和Java SE 1.7一起运行。