WindowBuilder的对包含匿名类的java代码支持不太好,
protected void createContents() {
shell = new Shell(SWT.NO_TRIM | SWT.ON_TOP);
shell.setSize(648, 480);
shell.setText("标签编译器");
shell.addKeyListener(keyListener);
// 匿名类方式初始化globalListenerManager
GlobalListenerManager globalListenerManager = new GlobalListenerManager(){
private static final long serialVersionUID = 1L;
{put(SWT.KeyDown,keyListener);}
};
Rectangle[] rects = new Rectangle[]{
new Rectangle(50,50,200,200),
new Rectangle(350,100,150,250),
new Rectangle(125,300,200,321)};
Image image = SWTResourceManager.getImage(this.getClass(),"/image/562c11dfa9ec8a13f075f10cf303918fa1ecc0eb.jpg");
shell.setLayout(new FillLayout(SWT.HORIZONTAL));
ActiveRectEditor editor = new ActiveRectEditor(shell, SWT.NONE,image,rects, globalListenerManager);
}
上面的代码在WindowBuilder的Design界面下报错了
点击左下角的红X显示了错误信息,如下图:
将globalListenerManager 的匿名类的初始化方式
GlobalListenerManager globalListenerManager = new GlobalListenerManager(){
private static final long serialVersionUID = 1L;
{put(SWT.KeyDown,keyListener);}
改为正常的初始化就好。
GlobalListenerManager globalListenerManager = new GlobalListenerManager();
globalListenerManager.put(SWT.KeyDown,keyListener);
其实这原来的代码是没毛病的,只是在windowbuilder的Design解释器无法支持。