Skip to content
This repository has been archived by the owner on Jul 10, 2018. It is now read-only.

NullPointerException when switch back dynamically to WindowsLookAndFeel #26

Closed
mtbadi39 opened this issue Mar 21, 2017 · 5 comments
Closed

Comments

@mtbadi39
Copy link

Hi;
When switch my application L&F dynamically from Metal, Nimbus or Windows to Substance LookAndFeel, it works fine with no problem.
When switch back from Substance LookAndFeel to Metal, Nimbus or Windows , the NullPointerException was occurred with the message :
Failed loading L&F: com.sun.java.swing.plaf.windows.WindowsLookAndFeel

For TEST purpose, i just updated UIManager Defaults to use all skinned Substance LookAndFeel.
Thanks in advance.

@kirill-grouchnikov
Copy link
Owner

That class has external dependencies, so I just explicitly registered a couple of Substance look and feel classes:

    UIManager.installLookAndFeel("Substance Business", SubstanceBusinessLookAndFeel.class.getName());
    UIManager.installLookAndFeel("Substance Mariner", SubstanceMarinerLookAndFeel.class.getName());
    UIManager.LookAndFeelInfo[] lafInfo = UIManager.getInstalledLookAndFeels();

I'm not seeing any exceptions thrown under the latest stable 7.0.01 release of Substance.

I'll need more info:

  1. Version of Substance
  2. Version of Java runtime
  3. Version of OS
  4. Full stack trace of the exception

@mtbadi39
Copy link
Author

Versions :

  • Substance 7.3 (from maven central)
  • Netbeans 8.2 with Java 7 on Windows 10

Stacktrace :
Failed loading L&F: com.sun.java.swing.plaf.windows.WindowsLookAndFeel java.lang.NullPointerException Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at org.pushingpixels.substance.internal.utils.SubstanceCoreUtilities.traceSubstanceApiUsage(SubstanceCoreUtilities.java:2117) at org.pushingpixels.substance.internal.utils.SubstanceColorSchemeUtilities.getColorScheme(SubstanceColorSchemeUtilities.java:268) at org.pushingpixels.substance.api.renderers.SubstanceDefaultListCellRenderer.getColorSchemeForState(SubstanceDefaultListCellRenderer.java:178) at org.pushingpixels.substance.api.renderers.SubstanceDefaultListCellRenderer.getListCellRendererComponent(SubstanceDefaultListCellRenderer.java:127) at org.pushingpixels.substance.api.renderers.SubstanceDefaultComboBoxRenderer.getListCellRendererComponent(SubstanceDefaultComboBoxRenderer.java:110) at javax.swing.plaf.basic.BasicComboBoxUI.getDisplaySize(BasicComboBoxUI.java:1366) at org.pushingpixels.substance.internal.ui.SubstanceComboBoxUI.getMinimumSize(SubstanceComboBoxUI.java:362) at javax.swing.plaf.basic.BasicComboBoxUI.getPreferredSize(BasicComboBoxUI.java:923) at javax.swing.JComponent.getPreferredSize(JComponent.java:1662) at java.awt.FlowLayout.preferredLayoutSize(FlowLayout.java:414) at java.awt.Container.preferredSize(Container.java:1796) at java.awt.Container.getPreferredSize(Container.java:1780) at javax.swing.JComponent.getPreferredSize(JComponent.java:1664) at java.awt.BorderLayout.layoutContainer(BorderLayout.java:815) at java.awt.Container.layout(Container.java:1510) at java.awt.Container.doLayout(Container.java:1499) at java.awt.Container.validateTree(Container.java:1695) at java.awt.Container.validateTree(Container.java:1704) at java.awt.Container.validateTree(Container.java:1704) at java.awt.Container.validateTree(Container.java:1704) at java.awt.Container.validate(Container.java:1630) at javax.swing.RepaintManager$3.run(RepaintManager.java:711) at javax.swing.RepaintManager$3.run(RepaintManager.java:709) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76) at javax.swing.RepaintManager.validateInvalidComponents(RepaintManager.java:708) at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1731) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756) at java.awt.EventQueue.access$500(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:709) at java.awt.EventQueue$3.run(EventQueue.java:703) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:726) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

How to reproduce :

  • Clone UIManager Defaults (its a netbeans/maven project)
  • Run ...
  • Select an item from the ComboBox
  • From Look & Feel Menu select Substance LookAndFeel => all fine (no problem)
  • Next, select Windows LookAndFeel => oops (NullPointerException).

@kirill-grouchnikov
Copy link
Owner

No idea what is Substance 7.3 from Maven. At some point Substance was forked into Insubstantial where the development continued without my involvement. I also don't publish binaries to Maven.

Unless this is happening with the latest official Substance release 7.0.01 that you can find in the /drop folder in here, there's nothing for me to fix.

@mtbadi39
Copy link
Author

Unless this is happening with the latest official Substance release 7.0.01 that you can find in the /drop folder in here, there's nothing for me to fix.

Sorry, its now happening with the latest official Substance release 7.0.01 !!

How to reproduce :

  • Clone UIManager Defaults (its a netbeans/maven project)
  • Download and manually install artifacts : substance-7.0.01.jar and trident-1.4.jar
  • Run ...
  • Select an item from the ComboBox ;
  • From Look & Feel Menu switch between Substance LookAndFeel(s) => all fine (no problem)
  • Now, switch back to to Metal, Nimbus or Windows LookAndFeel => and Oops (NullPointerException).

Edit : from StackTrace, the NullPointerException occured at line 1949 in org.pushingpixels.substance.internal.utils.SubstanceCoreUtilities.java :

The (w) is null (not a Frame nor a Dialog).

@kirill-grouchnikov
Copy link
Owner

ChangeLookAndFeelAction.run calls defaults.resetComponents() in between UIManager.setLookAndFeel and SwingUtilities.updateComponentTreeUI.

That means that while a new look and feel has been set, the existing UI components have not been properly updated to use UI delegates from that look and feel. Substance UI delegates can not be used under a non-Substance look-and-feel.

Switch the order like this:

                    defaults.resetComponents();
                    UIManager.setLookAndFeel(laf);

and the crash is gone

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants