错误: org.eclipse.swt.SWTException: Subclassing not allowed
[img]http://dl.iteye.com/upload/attachment/362293/c513312c-2456-32f8-95a4-1a381dbcdb5f.jpg[/img]
创建一个继承Shell的类BorderTextShell后出错
因为在BorderTextShell构造方法中,
要调用父类构造方法:
其中,checkSubclass ()方法继承自Decoration类,用来验证子类是否存在于org.eclipse.swt.widgets包内.
若不在此包内,则报错.
解决办法:
1. package org.eclipse.swt.widgets;
2. 重写checkSubclass ()方法,方法体为空.即在子类中添加:
3. 在类中声明Shell类的一个实例.(OO原则: 多用组合,少用继承)
[img]http://dl.iteye.com/upload/attachment/362293/c513312c-2456-32f8-95a4-1a381dbcdb5f.jpg[/img]
创建一个继承Shell的类BorderTextShell后出错
因为在BorderTextShell构造方法中,
super(display, style);
要调用父类构造方法:
public Shell (Display display, int style) {
this (display, null, style, 0, false);
}
Shell (Display display, Shell parent, int style, int /*long*/ handle, boolean embedded) {
super ();
checkSubclass ();
...
}
其中,checkSubclass ()方法继承自Decoration类,用来验证子类是否存在于org.eclipse.swt.widgets包内.
若不在此包内,则报错.
解决办法:
1. package org.eclipse.swt.widgets;
2. 重写checkSubclass ()方法,方法体为空.即在子类中添加:
protected void checkSubclass()
{
}
3. 在类中声明Shell类的一个实例.(OO原则: 多用组合,少用继承)