我遇到了SWT TreeCursor的问题。作为这个问题的例子,我将使用在Tree Cursor的eclipse网站上提供的“确切”示例:
现在,这个示例运行并且工作得很好,但是如果您在树中的任何位置单击,或者使用箭头键,从而使光标出现在屏幕上,在关闭程序时,会抛出异常堆栈跟踪:
Exception in thread "main" java.lang.IllegalArgumentException: Index out of bounds
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.Tree.getItem(Unknown Source)
at org.eclipse.swt.custom.TreeCursor$3.handleEvent(Unknown Source)
at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Display.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Widget.release(Unknown Source)
at org.eclipse.swt.widgets.TreeItem.release(Unknown Source)
at org.eclipse.swt.widgets.Tree.releaseChildren(Unknown Source)
at org.eclipse.swt.widgets.Widget.release(Unknown Source)
at org.eclipse.swt.widgets.Control.release(Unknown Source)
at org.eclipse.swt.widgets.Composite.releaseChildren(Unknown Source)
at org.eclipse.swt.widgets.Canvas.releaseChildren(Unknown Source)
at org.eclipse.swt.widgets.Decorations.releaseChildren(Unknown Source)
at org.eclipse.swt.widgets.Shell.releaseChildren(Unknown Source)
at org.eclipse.swt.widgets.Widget.release(Unknown Source)
at org.eclipse.swt.widgets.Control.release(Unknown Source)
at org.eclipse.swt.widgets.Widget.dispose(Unknown Source)
at org.eclipse.swt.widgets.Shell.closeWidget(Unknown Source)
at org.eclipse.swt.widgets.Shell.windowShouldClose(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 Snippet2.main(Snippet2.java:162)
这与您的代码无关。现在据我所知,这是SWT库中的一个问题,并在处理光标时发生。从堆栈跟踪看来,似乎在处理游标之前处理了Tree Items,因此当游标尝试访问TreeItem时,会发生异常。我目前正在使用一种解决方法,但我想知道是否有人知道如何处理这个问题。有什么想法?? !!
PS:我使用的是Mac OS X并使用SWT 4.2。