2013-03-21 18 views
6

Sto usando il look Nimbus & nella mia applicazione swing.

A volte, quando una finestra viene mostrato (con dialog.setVisible (true)) il Nimbus aspetto & feel getta la seguente eccezione:

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) 

Non ho idea di quando questo accade, è solo si verifica raramente, quando viene mostrata una finestra di dialogo.

ho cercato in Google (http://netbeans.org/bugzilla/show_bug.cgi?id=212757) ed è successo a più persone, ma nessuno sembra conoscere la causa di questo problema.

Questo è successo a qualcun altro? Forse è un bug Nimbus?

+1

per favore e dal tuo codice ???, OS nativo, JDK, JRE, solo la mia curiosità .... – mKorbel

+1

non necessariamente un bug Nimbus: potrebbe essere che qualche applicazione/codice di terze parti accidentalmente impostare una proprietà UI con il tipo di valore errato, fi 'UIManager.put (" Panel.backgroundPainter ", UIManager.get (" Panel.background "))" Chiunque sia il colpevole, questi buggy sono difficili da tracciare, la soluzione migliore è a) cercare di renderlo in qualche modo riproducibile b) debug – kleopatra

risposta

2

Che ha appena aiutato a rintracciare le cause di tali problemi riverniciare è di scartare il thread corrente in corrispondenza del punto nel nostro codice dell'applicazione che sta provocando l'aggiornamento dell'interfaccia utente che provoca in ultima analisi l'eccezione : LOGGER.debug("Current thread: " + Thread.currentThread());

Se un thread viene stampato che è qualcosa di diverso Discussione [AWT-EventQueue-0,6, principale] (dove i numeri possono essere qualsiasi cosa), allora si sta tentando di eseguire gli aggiornamenti dell'interfaccia utente al di fuori dello swing La discussione dell'evento e i problemi di riverniciatura sono quasi inevitabili.

L'utilizzo di SwingUtilities.invokeLater() o .invokeAndWait() può attenuare questo problema, ma normalmente questo problema farebbe riferimento a un errore nella progettazione dell'applicazione. Nel mio caso ho impostato (inutilmente) un renderer di celle per un JTree come parte dell'aggiornamento del modello ad albero.