我正在尝试从所有节点和连接中清除 Zest 图表,以便我可以使用新节点和连接重新绘制图表。为了实现我写了以下方法
public void clearGraph( Graph graph ) {
Object[] objects = graph.getConnections().toArray() ;
for (int i = 0 ; i < objects.length; i++){
GraphConnection graCon = (GraphConnection) objects[i];
graCon.dispose();
//graCon.setVisible(false);
}
objects = graph.getNodes().toArray();
for ( int i = 0 ; i < objects.length; i++){
GraphNode graNode = (GraphNode) objects[i];
graNode.dispose();
//graNode.setVisible(false);
}
}
这使我的程序因错误而崩溃
线程“主”org.eclipse.swt.SWTException 中的异常:已处理小部件
作为一种解决方法,我尝试将节点和连接设置为不可见,这可行,但不可见的对象似乎弄乱了我的热情布局,所以如果有一种方法可以实际处理节点和连接,我会更喜欢这种方式。
这是错误按摩
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.Item.getText(Unknown Source)
at com.mycom.timelineview.views.IndicatorFactorVisualisationView$2.mouseDoubleClick(IndicatorFactorVisualisationView.java:221)
at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source)
at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source)
at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
at com.mycom.timelineview.views.IndicatorFactorVisualisationView.indicatorFactorWindow(IndicatorFactorVisualisationView.java:249)
at com.mycom.timelineview.views.IndicatorFactorVisualisationView.<init>(IndicatorFactorVisualisationView.java:71)
at com.mycom.timelineview.views.SpiderWebMouseListener.chartMouseClicked(SpiderWebMouseListener.java:102)
at org.jfree.experimental.chart.swt.ChartComposite.mouseDown(ChartComposite.java:1621)
at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source)
at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source)
at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
at com.mycom.timelineview.views.SpiderWebView.createPartControl1(SpiderWebView.java:622)
at com.mycom.timelineview.views.InformationPlatformAppView2$7.handleEvent(InformationPlatformAppView2.java:628)
at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source)
at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
at com.mycom.timelineview.views.InformationPlatformAppView2.main(InformationPlatformAppView2.java:1330)
编辑:感谢 Baz,我发现了我的错误。鼠标侦听器必须在我之前配置的图形节点中搜索文本,因此程序当然必须崩溃。我更改了我的代码以避免它,现在 Baz 提出的方法可以完美运行。