Hello
I guess there is a threading problem in the code,
Janda, could you override the paintComponent() method of the component
where the exception is thrown
and make sure that it is called on the Event Dispatching Thread?
System.out.println("SwingUtilities.isEventDispatchThread() =
"+SwingUtilities.isEventDispatchThread());
Thanks
alexp
Hi Janda,
I don't understand how did you get NPE with provided stacktrace?
JComponent#paintComponent cannot get g = null, because of in the
previous JComponent#paintChildren method we have the following code:
Graphics cg = sg.create(cr.x, cr.y, cr.width,
cr.height);
cg.setColor(comp.getForeground()); // here
will be NPE when cg is null
I'm also not sure that it's valid situation to pass in the
JComponent#paintComponent method null as a Graphics. Could you please
provide a small test?
Regards, Pavel
protected void paintComponent(Graphics g) {
if (ui != null) {
Graphics scratchGraphics = (g == null) ? null : g.create();
try {
ui.update(scratchGraphics, this);
}
finally {
scratchGraphics.dispose(); // here
is NPE when input 'g' is null
}
}
}
uname -a
Linux linux-tp9a 2.6.25.20-0.4-default #1 SMP 2009-06-01 09:57:12
+0200 x86_64 x86_64 x86_64 GNU/Linux
java version "1.6.0_25"
Java(TM) SE Runtime Environment (build 1.6.0_25-b06)
Java HotSpot(TM) Server VM (build 20.0-b11, mixed mode)
Stack trace
AWT-EventQueue-0@2851, priority=6, in group 'main', status: 'RUNNING'
at javax.swing.JComponent.paintComponent(JComponent.java:755)
at javax.swing.JComponent.paint(JComponent.java:1,029)
at javax.swing.JComponent.paintChildren(JComponent.java:862)
at javax.swing.JComponent.paint(JComponent.java:1,038)
at javax.swing.JComponent.paintChildren(JComponent.java:862)
at javax.swing.JComponent.paint(JComponent.java:1,038)
at javax.swing.JComponent.paintChildren(JComponent.java:862)
at javax.swing.JComponent.paint(JComponent.java:1,038)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5,124)
at
javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:278)
at javax.swing.RepaintManager.paint(RepaintManager.java:1,224)
at javax.swing.JComponent._paintImmediately(JComponent.java:5,072)
at javax.swing.JComponent.paintImmediately(JComponent.java:4,882)
at
javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:785)
at
javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:713)
at
javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:693)
at
javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:125)
at
java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:641)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:602)
at java.awt.EventQueue$1.run(EventQueue.java:600)
at
java.security.AccessController.doPrivileged(AccessController.java:-1)
at
java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:611)
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)