gpt4 book ai didi

java - 如何解决 "Widget is disposed"问题?

转载 作者:行者123 更新时间:2023-12-01 16:33:27 25 4
gpt4 key购买 nike

在我看来,我在循环中创建按钮,并为每个按钮分配一个图像,并在 View 的构造函数中初始化这两个图像。

这里是按钮的代码:

for (int i = 0; i < 5; i++) {
final OButton button = new OButton(compositeT1, SWT.PUSH);
button.setText("T1" + i);
button.setData("1"+i);
GridData gd = new GridData(50,30);
button.setButtonRenderer(RedButtonRenderer.getInstance());
button.setLayoutData(gd);
if(!tournees.contains(button.getData().toString())){
button.setToolTipText("Livraison");
button.setImage(imgCamion);
}else{
button.setToolTipText("Appel");
button.setImage(imgCasque);

}
button.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
int tourneeInt = Integer.parseInt(button.getData().toString());
if (button.getImage().equals(imgCasque)) {
openAppelEditor(button.getData().toString());
}else if(tourneeInt == 12 || tourneeInt == 13 || tourneeInt == 14){
openLivraisonEditor(String.valueOf(tourneeInt - 2),button.getData().toString());
}else if(tourneeInt == 10) {
openLivraisonEditor("43",button.getData().toString());
}else if (tourneeInt == 11 ){
openLivraisonEditor("44",button.getData().toString());
}


}
@Override
public void widgetDefaultSelected(SelectionEvent e) {}
});

我还添加了函数 dispose() :

@Override
public void dispose() {
super.dispose();
this.imgCamion.dispose();
this.imgCasque.dispose();
}

问题是当我关闭 View 并重新打开它时,我收到错误:“小部件已处置”:

这是错误行:

!MESSAGE 无法创建 View ID ...../SelectionTourneePortefeuilleView: 小部件已处置
!堆栈0

org.eclipse.swt.SWTException: Widget is disposed
at org.eclipse.swt.SWT.error(SWT.java:4361)
at org.eclipse.swt.SWT.error(SWT.java:4276)
at org.eclipse.swt.SWT.error(SWT.java:4247)
at org.eclipse.swt.widgets.Widget.error(Widget.java:468)
at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:340)
at org.mihalis.opal.obutton.OButton.getImage(Unknown Source)
at org.mihalis.opal.obutton.AbstractButtonRenderer.createDisabledImage(Unknown Source)
at org.mihalis.opal.obutton.OButton.setImage(Unknown Source)
at com.croquegel.crm.vente.gestionportefeuille.view.SelectionTourneePortefeuilleView.createButtons(SelectionTourneePortefeuilleView.java:582)
at com.croquegel.crm.vente.gestionportefeuille.view.SelectionTourneePortefeuilleView.createPartControl(SelectionTourneePortefeuilleView.java:347)
at org.eclipse.ui.internal.ViewReference.createPartHelper(ViewReference.java:386)
at org.eclipse.ui.internal.ViewReference.createPart(ViewReference.java:240)
at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:595)
at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:315)
at org.eclipse.ui.internal.ViewPane.setVisible(ViewPane.java:534)
at org.eclipse.ui.internal.presentations.PresentablePart.setVisible(PresentablePart.java:180)
at org.eclipse.ui.internal.presentations.util.PresentablePartFolder.select(PresentablePartFolder.java:270)
at org.eclipse.ui.internal.presentations.util.LeftToRightTabOrder.select(LeftToRightTabOrder.java:65)
at org.eclipse.ui.internal.presentations.util.TabbedStackPresentation.selectPart(TabbedStackPresentation.java:473)
at org.eclipse.ui.internal.PartStack.refreshPresentationSelection(PartStack.java:1245)
at org.eclipse.ui.internal.PartStack.setSelection(PartStack.java:1198)
at org.eclipse.ui.internal.PartStack.showPart(PartStack.java:1597)
at org.eclipse.ui.internal.PartStack.createControl(PartStack.java:643)
at org.eclipse.ui.internal.PartStack.createControl(PartStack.java:570)
at org.eclipse.ui.internal.PartSashContainer.createControl(PartSashContainer.java:568)
at org.eclipse.ui.internal.PerspectiveHelper.activate(PerspectiveHelper.java:272)
at org.eclipse.ui.internal.Perspective.onActivate(Perspective.java:981)
at org.eclipse.ui.internal.WorkbenchPage.setPerspective(WorkbenchPage.java:3726)
at org.eclipse.ui.internal.WorkbenchPage.busySetPerspective(WorkbenchPage.java:1124)
at org.eclipse.ui.internal.WorkbenchPage.access$16(WorkbenchPage.java:1108)
at org.eclipse.ui.internal.WorkbenchPage$19.run(WorkbenchPage.java:3827)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.ui.internal.WorkbenchPage.setPerspective(WorkbenchPage.java:3825)
at org.eclipse.ui.internal.Workbench.showPerspective(Workbench.java:2875)

我如何知道哪个小部件已被处置?

我重新打开 View 后调试,图像的属性处理为false。

由于我正在开发 RCP 应用程序,因此我在相应的透视图中添加了 View 。

最佳答案

解决方案是将图像分配给线程中的按钮。

Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
//yourCode
});

为我工作。

关于java - 如何解决 "Widget is disposed"问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62006238/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com