Nimbus: java.lang.ClassCastException: javax.swing.plaf.nimbus.DerivedColor $ UIResource cannot be passed to javax.swing.Painter

I am using Nimbus in my swing application.

Sometimes, when a dialog is displayed (with dialog.setVisible (true)), Nimbus looks like this:

Caugth exception of type java.lang.ClassCastException with message javax.swing.plaf.nimbus.DerivedColor$UIResource cannot be cast to javax.swing.Painter java.lang.ClassCastException: javax.swing.plaf.nimbus.DerivedColor$UIResource cannot be cast to javax.swing.Painter at javax.swing.plaf.nimbus.NimbusStyle.getBackgroundPainter(NimbusStyle.java:708) at javax.swing.plaf.nimbus.SynthPainterImpl.paintBackground(SynthPainterImpl.java:99) at javax.swing.plaf.nimbus.SynthPainterImpl.paintPanelBackground(SynthPainterImpl.java:957) at javax.swing.plaf.synth.SynthPanelUI.update(SynthPanelUI.java:155) at javax.swing.JComponent.paintComponent(JComponent.java:778) at javax.swing.JComponent.paint(JComponent.java:1054) at javax.swing.JComponent.paintToOffscreen(JComponent.java:5221) at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1482) at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1413) at javax.swing.RepaintManager.paint(RepaintManager.java:1206) at javax.swing.JComponent._paintImmediately(JComponent.java:5169) at javax.swing.JComponent.paintImmediately(JComponent.java:4980) at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:770) at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:728) at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:677) at javax.swing.RepaintManager.access$700(RepaintManager.java:59) at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1621) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:721) at java.awt.EventQueue.access$200(EventQueue.java:103) at java.awt.EventQueue$3.run(EventQueue.java:682) at java.awt.EventQueue$3.run(EventQueue.java:680) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:691) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:155) at java.awt.WaitDispatchSupport$2.run(WaitDispatchSupport.java:182) at java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:221) at java.security.AccessController.doPrivileged(Native Method) at java.awt.WaitDispatchSupport.enter(WaitDispatchSupport.java:219) at java.awt.Dialog.show(Dialog.java:1077) at java.awt.Component.show(Component.java:1651) at java.awt.Component.setVisible(Component.java:1603) at java.awt.Window.setVisible(Window.java:1014) at java.awt.Dialog.setVisible(Dialog.java:1003) at java_awt_Dialog$setVisible.call(Unknown Source) at org.openfidelia.views.core.impl.WorkbenchImpl$_showViewAsDialog_closure1.doCall(WorkbenchImpl.groovy:375) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:226) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:52) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141) at org.openfidelia.views.core.impl.WorkbenchImpl$_showViewAsDialog_closure1.doCall(WorkbenchImpl.groovy) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1047) at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1110) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:877) at groovy.lang.Closure.call(Closure.java:412) at groovy.lang.Closure.call(Closure.java:406) at groovy.lang.Closure.run(Closure.java:490) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:241) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:721) at java.awt.EventQueue.access$200(EventQueue.java:103) at java.awt.EventQueue$3.run(EventQueue.java:682) at java.awt.EventQueue$3.run(EventQueue.java:680) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:691) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:155) at java.awt.WaitDispatchSupport$2.run(WaitDispatchSupport.java:182) at java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:221) at java.security.AccessController.doPrivileged(Native Method) at java.awt.WaitDispatchSupport.enter(WaitDispatchSupport.java:219) at java.awt.Dialog.show(Dialog.java:1077) at java.awt.Component.show(Component.java:1651) at java.awt.Component.setVisible(Component.java:1603) at java.awt.Window.setVisible(Window.java:1014) at java.awt.Dialog.setVisible(Dialog.java:1003) at java_awt_Dialog$setVisible.call(Unknown Source) at org.openfidelia.views.core.impl.WorkbenchImpl$_showViewAsDialog_closure1.doCall(WorkbenchImpl.groovy:375) 

I do not know when this happens, it is rare when a dialog is displayed.

I searched on Google ( http://netbeans.org/bugzilla/show_bug.cgi?id=212757 ) and this happened to a lot of people, but no one seems to know the reason for this problem.

Has this happened to anyone else? Maybe this is a Nimbus bug?

+7
source share
2 answers

What just helped me identify the causes of such redrawing problems is to unload the current thread at the point in our application code, which triggers a user interface update that ultimately throws an exception: LOGGER.debug("Current thread: " + Thread.currentThread());

If the stream is printed, it is something other than Thread [AWT-EventQueue-0.6, main] (where the numbers can be any), then you are trying to update the user interface outside the Swing Event stream and repainting problems are almost inevitable.

Using SwingUtilities.invokeLater() or .invokeAndWait() can mitigate this, but usually this problem indicates an application design error. In my case, I (unnecessarily) installed the cell renderer for JTree as part of updating the tree model.

+2
source

It looks like you are accessing / building swing components outside of EventDispatchThread. Take a look at this error: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6785663

+1
source

All Articles