JFXtras / jfxtras-styles

Java, JavaFX themes or look and feels. Currently contains JMetro theme.
https://pixelduke.com/java-javafx-theme-jmetro/
639 stars 144 forks source link

JMetro NPE when getOverridingStylesheets().add(source). Should throw instructive exception #213

Closed RealThanhpv closed 2 years ago

RealThanhpv commented 2 years ago

Hi, When I add a style sheet to the scene it works perfectly but it throw NPE when I add the same stylesheet to JMetro

public class Css {

    private Css() {
    }
    public static String getJMetroOverride(Style style){
        return Css.class.getResource("extension.css").toExternalForm();
    }
}
  entryScene.getStylesheets().add(Css.getJMetroOverride(Style.DARK)); //Line 1, works perfectly
        jMetro.getOverridingStylesheets().add(Css.getJMetroOverride(Style.DARK)); //Line 2, NPE 
        jMetro.setScene(entryScene);
        stage.setScene(entryScene);

Exception in thread "JavaFX Application Thread" java.lang.NullPointerException at org.jfxtras.styles.jmetro@11.6.15/jfxtras.styles.jmetro.JMetro.overridingStylesheetsChanged(JMetro.java:183) at javafx.base@18-ea/com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:164) at javafx.base@18-ea/com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73) at javafx.base@18-ea/javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:239) at javafx.base@18-ea/javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482) at javafx.base@18-ea/javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541) at javafx.base@18-ea/javafx.collections.ObservableListBase.endChange(ObservableListBase.java:211) at javafx.base@18-ea/javafx.collections.ModifiableObservableListBase.add(ModifiableObservableListBase.java:162) at java.base/java.util.AbstractList.add(AbstractList.java:111) at plantrek.fxui/plantrek.fxui.fxapp.DrawApp.start(DrawApp.java:51) at javafx.graphics@18-ea/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847) at javafx.graphics@18-ea/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484) at javafx.graphics@18-ea/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457) at java.base/java.security.AccessController.doPrivileged(Native Method) at javafx.graphics@18-ea/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456) at javafx.graphics@18-ea/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)

RealThanhpv commented 2 years ago

Overriding sheet should be add after scene or parent is set

dukke commented 2 years ago

I think your suggestion is a good idea. This has been fixed. There will now be a more instructive exception.