带有 WindowBuilder 的自定义 JPanel 导致崩溃
的部分代码是:
JPanel panel = new JPanel();
我使用 WindowBuilder Pro 设计了一个表单,生成 我正在尝试使用绘制方法制作我自己的 JPanel:
private class DisplayPanel extends JPanel {
public DisplayPanel() {
// TODO Auto-generated constructor stub
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
//Paint the graph. Note that x is to the right, y is down.
g.setColor(Color.black);
g.drawRect(0,0,this.getWidth()-1,this.getHeight()-1);
}
@Override
public boolean mouseDrag(Event evt, int x, int y) {
System.out.println(x+", "+y);
return false;
}
}
不幸的是,将构造函数更改为:
JPanel panel = new DisplayPanel();
切换到设计视图时会导致错误:
WindowBuilder encountered unexpected internal error.
This could be caused by a WindowBuilder bug or by a misconfiguration issue, conflict, partial update, etc.
java.lang.NullPointerException: Argument must not be null
Stack trace:
java.lang.NullPointerException: Argument must not be null
at javax.swing.Spring.checkArg(Spring.java:671)
at javax.swing.Spring.width(Spring.java:640)
at javax.swing.SpringLayout.applyDefaults(SpringLayout.java:1074)
at javax.swing.SpringLayout.putConstraints(SpringLayout.java:1105)
at javax.swing.SpringLayout.getConstraints(SpringLayout.java:1140)
at javax.swing.SpringLayout$SpringProxy.getConstraint(SpringLayout.java:829)
at javax.swing.SpringLayout$SpringProxy.isCyclic(SpringLayout.java:853)
at javax.swing.SpringLayout.isCyclic(SpringLayout.java:907)
at javax.swing.Spring$CompoundSpring.isCyclic(Spring.java:460)
at javax.swing.SpringLayout.isCyclic(SpringLayout.java:907)
at javax.swing.SpringLayout.abandonCycles(SpringLayout.java:919)
at javax.swing.SpringLayout.layoutContainer(SpringLayout.java:1209)
at java.awt.Container.layout(Container.java:1421)
at java.awt.Container.doLayout(Container.java:1410)
at java.awt.Container.validateTree(Container.java:1507)
at java.awt.Container.validateTree(Container.java:1513)
at java.awt.Container.validateTree(Container.java:1513)
at java.awt.Container.validateTree(Container.java:1513)
at java.awt.Container.validate(Container.java:1480)
at org.eclipse.wb.internal.swing.model.component.top.WindowTopBoundsSupport.apply(WindowTopBoundsSupport.java:67)
at org.eclipse.wb.core.model.AbstractComponentInfo.refresh_afterCreate(AbstractComponentInfo.java:241)
at org.eclipse.wb.core.model.ObjectInfo.refreshCreate0(ObjectInfo.java:535)
at org.eclipse.wb.core.model.ObjectInfo.access$0(ObjectInfo.java:529)
at org.eclipse.wb.core.model.ObjectInfo$5$1.run(ObjectInfo.java:486)
at org.eclipse.wb.internal.core.utils.execution.ExecutionUtils.runDesignTime(ExecutionUtils.java:139)
at org.eclipse.wb.core.model.ObjectInfo$5.run(ObjectInfo.java:484)
at org.eclipse.wb.internal.swing.utils.SwingUtils$2.run(SwingUtils.java:76)
at org.eclipse.wb.internal.swing.utils.SwingUtils.invokeLaterAndWait(SwingUtils.java:180)
at org.eclipse.wb.internal.swing.utils.SwingUtils.runLaterAndWait(SwingUtils.java:73)
at org.eclipse.wb.internal.swing.model.component.ComponentInfo.doRefresh(ComponentInfo.java:118)
at org.eclipse.wb.core.model.ObjectInfo.refresh(ObjectInfo.java:482)
at org.eclipse.wb.internal.core.editor.DesignPage.internal_refreshGEF(DesignPage.java:559)
at org.eclipse.wb.internal.core.editor.DesignPage.access$9(DesignPage.java:501)
at org.eclipse.wb.internal.core.editor.DesignPage$8$1.run(DesignPage.java:434)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:179)
at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:150)
at org.eclipse.swt.widgets.Display.syncExec(Display.java:4113)
at org.eclipse.wb.internal.core.editor.DesignPage$8.run(DesignPage.java:431)
at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:464)
at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:372)
at org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDialog.java:507)
at org.eclipse.wb.internal.core.editor.DesignPage.internal_refreshGEF_withProgress(DesignPage.java:450)
at org.eclipse.wb.internal.core.editor.DesignPage.internal_refreshGEF(DesignPage.java:400)
at org.eclipse.wb.internal.core.editor.UndoManager.refreshDesignerEditor(UndoManager.java:381)
at org.eclipse.wb.internal.core.editor.UndoManager.activate(UndoManager.java:90)
at org.eclipse.wb.internal.core.editor.DesignPage.handleActiveState_True(DesignPage.java:248)
at org.eclipse.wb.internal.core.editor.DesignPage.handleActiveState(DesignPage.java:226)
at org.eclipse.wb.internal.core.editor.multi.DefaultMultiMode.showPage(DefaultMultiMode.java:125)
at org.eclipse.wb.internal.core.editor.multi.DefaultMultiMode$1.widgetSelected(DefaultMultiMode.java:63)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:228)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1176)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1200)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1185)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1025)
at org.eclipse.swt.custom.CTabFolder.setSelection(CTabFolder.java:3256)
at org.eclipse.swt.custom.CTabFolder.onMouse(CTabFolder.java:2045)
at org.eclipse.swt.custom.CTabFolder$1.handleEvent(CTabFolder.java:323)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1176)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3493)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3112)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2405)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2369)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2221)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:500)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:493)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:113)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:194)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:368)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:559)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
这是一个错误吗?或者有其他方法可以做到这一点吗?
我尝试在 gui 设计器中设置子类,右键单击 Morph-subclass,但是当我选择 DisplayPanel 时,会出现错误:
new DisplayPanel((Mainwin) null) is not valid source for component creation, it references not existing constructor.
I have designed a form using WindowBuilder Pro, part of the generated code is:
JPanel panel = new JPanel();
I'm trying to make my own JPanel, with paint method:
private class DisplayPanel extends JPanel {
public DisplayPanel() {
// TODO Auto-generated constructor stub
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
//Paint the graph. Note that x is to the right, y is down.
g.setColor(Color.black);
g.drawRect(0,0,this.getWidth()-1,this.getHeight()-1);
}
@Override
public boolean mouseDrag(Event evt, int x, int y) {
System.out.println(x+", "+y);
return false;
}
}
Unfortunately, changing the constructor to:
JPanel panel = new DisplayPanel();
causes an error when switching to design view:
WindowBuilder encountered unexpected internal error.
This could be caused by a WindowBuilder bug or by a misconfiguration issue, conflict, partial update, etc.
java.lang.NullPointerException: Argument must not be null
Stack trace:
java.lang.NullPointerException: Argument must not be null
at javax.swing.Spring.checkArg(Spring.java:671)
at javax.swing.Spring.width(Spring.java:640)
at javax.swing.SpringLayout.applyDefaults(SpringLayout.java:1074)
at javax.swing.SpringLayout.putConstraints(SpringLayout.java:1105)
at javax.swing.SpringLayout.getConstraints(SpringLayout.java:1140)
at javax.swing.SpringLayout$SpringProxy.getConstraint(SpringLayout.java:829)
at javax.swing.SpringLayout$SpringProxy.isCyclic(SpringLayout.java:853)
at javax.swing.SpringLayout.isCyclic(SpringLayout.java:907)
at javax.swing.Spring$CompoundSpring.isCyclic(Spring.java:460)
at javax.swing.SpringLayout.isCyclic(SpringLayout.java:907)
at javax.swing.SpringLayout.abandonCycles(SpringLayout.java:919)
at javax.swing.SpringLayout.layoutContainer(SpringLayout.java:1209)
at java.awt.Container.layout(Container.java:1421)
at java.awt.Container.doLayout(Container.java:1410)
at java.awt.Container.validateTree(Container.java:1507)
at java.awt.Container.validateTree(Container.java:1513)
at java.awt.Container.validateTree(Container.java:1513)
at java.awt.Container.validateTree(Container.java:1513)
at java.awt.Container.validate(Container.java:1480)
at org.eclipse.wb.internal.swing.model.component.top.WindowTopBoundsSupport.apply(WindowTopBoundsSupport.java:67)
at org.eclipse.wb.core.model.AbstractComponentInfo.refresh_afterCreate(AbstractComponentInfo.java:241)
at org.eclipse.wb.core.model.ObjectInfo.refreshCreate0(ObjectInfo.java:535)
at org.eclipse.wb.core.model.ObjectInfo.access$0(ObjectInfo.java:529)
at org.eclipse.wb.core.model.ObjectInfo$5$1.run(ObjectInfo.java:486)
at org.eclipse.wb.internal.core.utils.execution.ExecutionUtils.runDesignTime(ExecutionUtils.java:139)
at org.eclipse.wb.core.model.ObjectInfo$5.run(ObjectInfo.java:484)
at org.eclipse.wb.internal.swing.utils.SwingUtils$2.run(SwingUtils.java:76)
at org.eclipse.wb.internal.swing.utils.SwingUtils.invokeLaterAndWait(SwingUtils.java:180)
at org.eclipse.wb.internal.swing.utils.SwingUtils.runLaterAndWait(SwingUtils.java:73)
at org.eclipse.wb.internal.swing.model.component.ComponentInfo.doRefresh(ComponentInfo.java:118)
at org.eclipse.wb.core.model.ObjectInfo.refresh(ObjectInfo.java:482)
at org.eclipse.wb.internal.core.editor.DesignPage.internal_refreshGEF(DesignPage.java:559)
at org.eclipse.wb.internal.core.editor.DesignPage.access$9(DesignPage.java:501)
at org.eclipse.wb.internal.core.editor.DesignPage$8$1.run(DesignPage.java:434)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:179)
at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:150)
at org.eclipse.swt.widgets.Display.syncExec(Display.java:4113)
at org.eclipse.wb.internal.core.editor.DesignPage$8.run(DesignPage.java:431)
at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:464)
at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:372)
at org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDialog.java:507)
at org.eclipse.wb.internal.core.editor.DesignPage.internal_refreshGEF_withProgress(DesignPage.java:450)
at org.eclipse.wb.internal.core.editor.DesignPage.internal_refreshGEF(DesignPage.java:400)
at org.eclipse.wb.internal.core.editor.UndoManager.refreshDesignerEditor(UndoManager.java:381)
at org.eclipse.wb.internal.core.editor.UndoManager.activate(UndoManager.java:90)
at org.eclipse.wb.internal.core.editor.DesignPage.handleActiveState_True(DesignPage.java:248)
at org.eclipse.wb.internal.core.editor.DesignPage.handleActiveState(DesignPage.java:226)
at org.eclipse.wb.internal.core.editor.multi.DefaultMultiMode.showPage(DefaultMultiMode.java:125)
at org.eclipse.wb.internal.core.editor.multi.DefaultMultiMode$1.widgetSelected(DefaultMultiMode.java:63)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:228)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1176)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1200)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1185)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1025)
at org.eclipse.swt.custom.CTabFolder.setSelection(CTabFolder.java:3256)
at org.eclipse.swt.custom.CTabFolder.onMouse(CTabFolder.java:2045)
at org.eclipse.swt.custom.CTabFolder$1.handleEvent(CTabFolder.java:323)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1176)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3493)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3112)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2405)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2369)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2221)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:500)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:493)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:113)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:194)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:368)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:559)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
Is this a bug? Or is there a different way to do this?
I tried setting the subclass in the gui designer, with right-click, Morph-subclass, but when I select DisplayPanel it gives an error:
new DisplayPanel((Mainwin) null) is not valid source for component creation, it references not existing constructor.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我将 DisplayPanel 从窗口类中的私有类移至单独的类。这样就消除了错误。
I moved the DisplayPanel from a private class in the window class, to a separate class. This eliminates the error.
有同样的问题。
似乎 JTree 给我造成了这个错误。
我将 JTree 从静态更改为“非静态”,错误消失了。
当我尝试将其改回静态时,错误仍然消失了......
(没有进行其他更改!)
我认为这只是一个窗口生成器错误。
Had the same issue.
Seems like a JTree caused that error for me.
I changed the JTree from static to "not static" and the error was gone.
When i tried for fun to change it back to static error was still gone...
(No other changes were made!)
I think that it is just a window builder bug.