我正在使用AWT_SWT帧桥嵌入图形 API 来 eclipse 插件应用程序。一切正常,但我在移动或滚动框架时面临闪烁/重新绘制问题。我做了很多研发,尝试了一些解决方案,比如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);
请帮助我找到任何解决方案。提前谢谢。
如 eclipse 角文章 Swing/SWT 集成部分"创建根窗格容器"中所述,您必须将重量级组件设置为帧的第一个子级。只有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 一起运行。