Nimbus:java.lang.ClassCastException:javax.swing.plaf.nimbus.DerivedColor $UIResource无法强制转换为javax.swing.Painter

前端之家收集整理的这篇文章主要介绍了Nimbus:java.lang.ClassCastException:javax.swing.plaf.nimbus.DerivedColor $UIResource无法强制转换为javax.swing.Painter前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用Nimbus外观&感觉在我的挥杆应用程序.

有时候,当显示一个对话框(带有dialog.setVisible(true))时,Nimbus外观&感觉抛出以下异常:

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)

我不知道何时发生这种情况,只是在显示对话框时很少发生.

我一直在谷歌搜索(http://netbeans.org/bugzilla/show_bug.cgi?id=212757),它发生在更多的人身上,但似乎没有人知道这个问题的原因.

这有发生在其他人身上吗?也许这是一个Nimbus的bug?

@H_403_13@解决方法
刚刚帮助我找出这些重绘问题的原因的是在我们的应用程序代码中转出当前线程,触发最终导致异常的UI更新:
LOGGER.debug(“当前线程:”Thread.currentThread());

如果打印出的线程不是Thread [AWT-EventQueue-0,6,main](数字可以是任何东西),那么你试图在Swing Event Dispatch Thread之外执行UI更新并重新绘制问题几乎不可避免.

使用SwingUtilities.invokeLater()或.invokeAndWait()可以缓解这种情况,但通常这个问题会指出应用程序设计中的错误.就我而言,我(不必要地)为JTree设置了一个单元格渲染器,作为更新树模型的一部分.

原文链接:https://www.f2er.com/java/129352.html

猜你在找的Java相关文章