This bug has been annoying me for a while, and I can’t seem to track down a good way to fix it. Many of my commands in my editor require the scene graph view (a JTree of all the nodes) to be rebuilt as nodes are added, deleted, moved etc. For the time being I typically do a brute force update when major changes are performed since its much easier (and I havn’t run into any problems yet).
However what this ends up doing is that I’m totally rebuilding the tree nodes (only the root node is persistant) and frequently Swing is trying to paint the JTree at the same time, so hits a null pointer (stack below). Now the line actually points to:
component = currentCellRenderer.getTreeCellRendererComponent
(tree, path.getLastPathComponent(),
tree.isRowSelected(row), isExpanded, isLeaf, row,
(leadIndex == row));
which is unfortunatly rather vauge as it could be multiple objects here that are the cause. Trying to grab it in the debugger is tricky since it only gets caught in a finally block, and manually stepping though means that the exception doesn’t happen because it disrupts the timing and redraw events. /me needs a multi monitor setup to get around this…
The only thing i can think of doing is a setVisible(false) on the tree before the tree update happens, yet this doesn’t seem to fix anything. Anyone any suggestions on how to fix this?
java.lang.NullPointerException
at javax.swing.plaf.basic.BasicTreeUI.paintRow(BasicTreeUI.java:1375)
at javax.swing.plaf.basic.BasicTreeUI.paint(BasicTreeUI.java:1171)
at javax.swing.plaf.ComponentUI.update(ComponentUI.java:142)
at javax.swing.JComponent.paintComponent(JComponent.java:537)
at javax.swing.JComponent.paint(JComponent.java:804)
at javax.swing.JComponent.paintChildren(JComponent.java:643)
at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4742)
at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4688)
at javax.swing.JComponent._paintImmediately(JComponent.java:4632)
at javax.swing.JComponent.paintImmediately(JComponent.java:4464)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:404)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:117)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:443)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:144)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)