将 JTable 添加到对话框内的窗格中,打包时会抛出 NPE
我创建了一个JDialog
。当它出现时,我有一个 JTabbedPane
,上面有几个 FormPanel
。表单面板作为表单文件加载(我使用 Abeille 创建表单。)没有问题,直到我尝试将 JTable
添加到其中一个表单(再次通过 Abeille)。我像添加其余选项卡一样添加表单,但是当我运行 dialog. pack
,它会抛出一个NullPointerException
。该表单内的表格似乎不是 null
因为我可以从中获取值。我看不出是什么导致了 null
。
private JDialog m_dialog;
private FormPanel m_panelForm;
private FormPanel m_tableEditorForm;
private FormPanel m_fieldEditorForm;
private FormPanel m_seedDataEditorForm;
JFrame appFrame = App.getInstance().getFrame();
m_dialog = new JDialog(appFrame, "Dialog Title"), true);
m_dialog.setName("Dialog"));
m_dialog.setLocationRelativeTo(appFrame);
// Load dialog layout
m_panelForm = getFormPanel("DLG_EDIT_PANEL");
m_tableEditorForm = getFormPanel("DLG_TABLE_EDITOR");
m_fieldEditorForm = getFormPanel("DLG_FIELD_EDITOR");
m_seedDataEditorForm = getFormPanel("DLG_SEED_DATA_EDITOR");
JTabbedPane pane = m_panelForm.getTabbedPane("editPane");
//Set up the tabs
pane.insertTab("Table", null, m_tableEditorForm, null, 0);
pane.insertTab("Field", null, m_fieldEditorForm, null, 1);
pane.insertTab("Seed", null, m_seedDataEditorForm, null, 2);
m_panelForm.reset();
m_dialog.setContentPane(m_panelForm);
m_dialog.pack();
第三个插入物,即所谓的“种子”,就是将其吹灭的那个;如果我注释掉该行,其他选项卡会显示正常。同样,如果我从 Abeille 的表单中删除 JTable
,选项卡就会显示正常。
请注意,columnCount
和 rowCount
默认为 2。另请注意,如果我关闭 pack,我会关闭 JDialog 的
抛出同样的错误。setVisible
任何帮助将不胜感激;我在 Swing 上还不错,但还差得远。
堆栈跟踪:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at com.jeta.open.support.DefaultComponentFinder.unregisterComponent(Unknown Source) at com.jeta.open.support.DefaultComponentFinder.componentRemoved(Unknown Source) at java.awt.AWTEventMulticaster.componentRemoved(AWTEventMulticaster.java:193) at java.awt.Container.processContainerEvent(Container.java:2070) at java.awt.Container.processEvent(Container.java:2038) at java.awt.Component.dispatchEventImpl(Component.java:4652) at java.awt.Container.dispatchEventImpl(Container.java:2099) at java.awt.Component.dispatchEvent(Component.java:4482) at java.awt.Container.remove(Container.java:1162) at java.awt.Container.remove(Container.java:1198) at java.awt.Container.addImpl(Container.java:1046) at java.awt.Container.add(Container.java:927) at javax.swing.plaf.basic.BasicScrollPaneUI.updateColumnHeader(BasicScrollPaneUI.java:606) at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.scrollPanePropertyChange(BasicScrollPaneUI.java:1102) at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.propertyChange(BasicScrollPaneUI.java:1079) at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:339) at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:276) at java.awt.Component.firePropertyChange(Component.java:8154) at javax.swing.JScrollPane.setColumnHeader(JScrollPane.java:1095) at javax.swing.JScrollPane.setColumnHeaderView(JScrollPane.java:1120) at javax.swing.JTable.configureEnclosingScrollPane(JTable.java:713) at javax.swing.JTable.addNotify(JTable.java:684) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at javax.swing.JRootPane.addNotify(JRootPane.java:739) at java.awt.Container.addNotify(Container.java:2578) at java.awt.Window.addNotify(Window.java:663) at java.awt.Dialog.addNotify(Dialog.java:743) at java.awt.Window.pack(Window.java:704) at com.follett.fsc.core.utils.schema.workbench.gui.dialogs.EditTableDialog.showDialog(EditTableDialog.java:108) at com.follett.fsc.core.utils.schema.workbench.gui.components.Tab.doEditTableRow(Tab.java:1354) at com.follett.fsc.core.utils.schema.workbench.gui.components.Tab.doEditRow(Tab.java:1437) at com.follett.fsc.core.utils.schema.workbench.gui.components.Tab$17$1.run(Tab.java:1016) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:642) at java.awt.EventQueue.access$000(EventQueue.java:85) at java.awt.EventQueue$1.run(EventQueue.java:603) at java.awt.EventQueue$1.run(EventQueue.java:601) at java.security.AccessController.doPrivileged(Native Method) at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87) at java.awt.EventQueue.dispatchEvent(EventQueue.java:612) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161) at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
I have created a JDialog
. When it comes up, I have a JTabbedPane
that has several FormPanel
s on it. The form panels are loaded in as a form file (I used Abeille to create the forms.) I have had no problems until I tried to add a JTable
to one of the forms (again, through Abeille.) I add the form like I did the rest of the tabs, but when I run dialog.pack
, it throws a NullPointerException
. The table inside that form does not appear to be null
as I can get values from it. I cannot see what is causing the null
.
private JDialog m_dialog;
private FormPanel m_panelForm;
private FormPanel m_tableEditorForm;
private FormPanel m_fieldEditorForm;
private FormPanel m_seedDataEditorForm;
JFrame appFrame = App.getInstance().getFrame();
m_dialog = new JDialog(appFrame, "Dialog Title"), true);
m_dialog.setName("Dialog"));
m_dialog.setLocationRelativeTo(appFrame);
// Load dialog layout
m_panelForm = getFormPanel("DLG_EDIT_PANEL");
m_tableEditorForm = getFormPanel("DLG_TABLE_EDITOR");
m_fieldEditorForm = getFormPanel("DLG_FIELD_EDITOR");
m_seedDataEditorForm = getFormPanel("DLG_SEED_DATA_EDITOR");
JTabbedPane pane = m_panelForm.getTabbedPane("editPane");
//Set up the tabs
pane.insertTab("Table", null, m_tableEditorForm, null, 0);
pane.insertTab("Field", null, m_fieldEditorForm, null, 1);
pane.insertTab("Seed", null, m_seedDataEditorForm, null, 2);
m_panelForm.reset();
m_dialog.setContentPane(m_panelForm);
m_dialog.pack();
The third insert, the one called "Seed" is the one that blows it out; if I comment out the line the other tabs show up fine. Similarly, if I remove the JTable
from the form in Abeille the tab shows up fine.
Note the columnCount
and rowCount
defaults to 2. Also note that if I turn off pack, I have a setVisible
off of the JDialog
that throws the same error.
Any help would be appreciated; I'm okay at Swing but far from good.
Stacktrace:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at com.jeta.open.support.DefaultComponentFinder.unregisterComponent(Unknown Source) at com.jeta.open.support.DefaultComponentFinder.componentRemoved(Unknown Source) at java.awt.AWTEventMulticaster.componentRemoved(AWTEventMulticaster.java:193) at java.awt.Container.processContainerEvent(Container.java:2070) at java.awt.Container.processEvent(Container.java:2038) at java.awt.Component.dispatchEventImpl(Component.java:4652) at java.awt.Container.dispatchEventImpl(Container.java:2099) at java.awt.Component.dispatchEvent(Component.java:4482) at java.awt.Container.remove(Container.java:1162) at java.awt.Container.remove(Container.java:1198) at java.awt.Container.addImpl(Container.java:1046) at java.awt.Container.add(Container.java:927) at javax.swing.plaf.basic.BasicScrollPaneUI.updateColumnHeader(BasicScrollPaneUI.java:606) at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.scrollPanePropertyChange(BasicScrollPaneUI.java:1102) at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.propertyChange(BasicScrollPaneUI.java:1079) at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:339) at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:276) at java.awt.Component.firePropertyChange(Component.java:8154) at javax.swing.JScrollPane.setColumnHeader(JScrollPane.java:1095) at javax.swing.JScrollPane.setColumnHeaderView(JScrollPane.java:1120) at javax.swing.JTable.configureEnclosingScrollPane(JTable.java:713) at javax.swing.JTable.addNotify(JTable.java:684) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at java.awt.Container.addNotify(Container.java:2578) at javax.swing.JComponent.addNotify(JComponent.java:4685) at javax.swing.JRootPane.addNotify(JRootPane.java:739) at java.awt.Container.addNotify(Container.java:2578) at java.awt.Window.addNotify(Window.java:663) at java.awt.Dialog.addNotify(Dialog.java:743) at java.awt.Window.pack(Window.java:704) at com.follett.fsc.core.utils.schema.workbench.gui.dialogs.EditTableDialog.showDialog(EditTableDialog.java:108) at com.follett.fsc.core.utils.schema.workbench.gui.components.Tab.doEditTableRow(Tab.java:1354) at com.follett.fsc.core.utils.schema.workbench.gui.components.Tab.doEditRow(Tab.java:1437) at com.follett.fsc.core.utils.schema.workbench.gui.components.Tab$17$1.run(Tab.java:1016) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:642) at java.awt.EventQueue.access$000(EventQueue.java:85) at java.awt.EventQueue$1.run(EventQueue.java:603) at java.awt.EventQueue$1.run(EventQueue.java:601) at java.security.AccessController.doPrivileged(Native Method) at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87) at java.awt.EventQueue.dispatchEvent(EventQueue.java:612) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161) at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论