在我的SWT应用程序中,我使用SWT文本在基于shell的结构中输入项目编号。源代码存在here。
我希望没什么特别的:
inputNumber = new Text(group, SWT.SINGLE | SWT.BORDER);
// platform independent key handling for ENTER, TAB, ...
// TODO change bad listener with a better one
inputNumber.addListener(SWT.Traverse, event -> {
if (!inputNumber.getText().trim().equals("")) {
if ((event.stateMask & SWT.SHIFT) == SWT.SHIFT && event.detail == SWT.TRAVERSE_RETURN) {
actionBtnOkAndExit();
} else if (event.detail == SWT.TRAVERSE_RETURN) {
actionBtnOk();
}
}
});
当用户填写插入符号(在mac?上)'^'并且我点击转义符来关闭shell时,JVM崩溃时出现以下错误消息。使用留在其上的退格键''的键可以完成相同的操作。
2017-10-11 22:35:44.704 java[9862:954273] *** WARNING: Method userSpaceScaleFactor in class NSWindow is deprecated on 10.7 and later. It should not be used in new applications. Use convertRectToBacking: instead.
2017-10-11 22:35:44.709 java[9862:954273] *** WARNING: Method userSpaceScaleFactor
in class NSView is deprecated on 10.7 and later. It should not be used in new
applications. Use convertRectToBacking: instead.
Exception in thread "main" org.eclipse.swt.SWTException: Widget is disposed
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.widgets.Widget.error(Unknown Source)
at org.eclipse.swt.widgets.Widget.checkWidget(Unknown Source)
at org.eclipse.swt.widgets.Control.getShell(Unknown Source)
at org.eclipse.swt.widgets.Control.traversalCode(Unknown Source)
at org.eclipse.swt.widgets.Text.traversalCode(Unknown Source)
at org.eclipse.swt.widgets.Control.translateTraversal(Unknown Source)
at org.eclipse.swt.widgets.Control.keyDown(Unknown Source)
at org.eclipse.swt.widgets.Display.windowProc(Unknown Source)
at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
at org.eclipse.swt.widgets.Widget.callSuper(Unknown Source)
at org.eclipse.swt.widgets.Widget.windowSendEvent(Unknown Source)
at org.eclipse.swt.widgets.Shell.windowSendEvent(Unknown Source)
at org.eclipse.swt.widgets.Display.windowProc(Unknown Source)
at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
at org.eclipse.swt.widgets.Display.applicationSendEvent(Unknown Source)
at org.eclipse.swt.widgets.Display.applicationProc(Unknown Source)
at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method)
at org.eclipse.swt.internal.cocoa.NSApplication.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
at de.ryanthara.ja.rycon.ui.MainApplication.initUI(MainApplication.java:687)
at de.ryanthara.ja.rycon.ui.MainApplication.<init>(MainApplication.java:94)
at de.ryanthara.ja.rycon.ui.MainApplication.main(MainApplication.java:137)
Process finished with exit code 1
是否有人知道我的代码中缺少什么或这里出了什么问题?
从我的来源减少了最少的代码:
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class MinimumText {
public MinimumText(final Shell parent) {
GridLayout gridLayout = new GridLayout(1, true);
Shell innerShell = new Shell(parent, SWT.CLOSE | SWT.DIALOG_TRIM | SWT.MAX | SWT.TITLE | SWT.APPLICATION_MODAL);
innerShell.setSize(600, 400);
innerShell.setLayout(gridLayout);
new Text(innerShell, SWT.SINGLE | SWT.BORDER);
innerShell.setLocation(200, 100);
innerShell.open();
}
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout(1, false));
new MinimumText(shell);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
在按下转义键之前,文本字段会以这种方式显示。
最小例子的屏幕截图就是这样的。点击转义键时的行为相同。