In my own custom controls, I used to use something like this in the control's constructor to add the stylesheet to a control:
sceneProperty().addListener(new ChangeListener<Scene>() {
@Override
public void changed(ObservableValue<? extends Scene> observableValue, Scene scene, Scene scene1) {
if (scene1 != null) {
scene1.getStylesheets().add(getClass().getResource("/styles.css").toExternalForm());
}
}
});
I recently learned, that there is a method for this:
@Override
public String getUserAgentStylesheet() {
return getClass().getResource("/styles.css").toExternalForm();
}
However, if I use that method, I get a lot of warnings:
>
WARNING: com.sun.javafx.css.StyleHelper calculateValue Could not resolve '-fx-shadow-highlight-color' while resolving lookups for '-fx-background-color' from rule '*.text-field' in stylesheet jar:file:/C:/Program%20Files%20(x86)/Java/jdk1.7.0_06/jre/lib/jfxrt.jar!/com/sun/javafx/scene/control/skin/caspian/caspian.bss
WARNING: com.sun.javafx.css.StyleHelper calculateValue Could not resolve '-fx-text-inner-color' while resolving lookups for '-fx-text-fill' from rule '*.text-field' in stylesheet jar:file:/C:/Program%20Files%20(x86)/Java/jdk1.7.0_06/jre/lib/jfxrt.jar!/com/sun/javafx/scene/control/skin/caspian/caspian.bss
WARNING: com.sun.javafx.css.StyleHelper calculateValue Could not resolve '-fx-control-inner-background' while resolving lookups for '-fx-prompt-text-fill' from rule '*.text-field' in stylesheet jar:file:/C:/Program%20Files%20(x86)/Java/jdk1.7.0_06/jre/lib/jfxrt.jar!/com/sun/javafx/scene/control/skin/caspian/caspian.bss
WARNING: com.sun.javafx.css.StyleHelper calculateValue Could not resolve '-fx-accent' while resolving lookups for '-fx-highlight-fill' from rule '*.text-input' in stylesheet jar:file:/C:/Program%20Files%20(x86)/Java/jdk1.7.0_06/jre/lib/jfxrt.jar!/com/sun/javafx/scene/control/skin/caspian/caspian.bss
WARNING: com.sun.javafx.css.StyleHelper calculateValue Could not resolve '-fx-text-base-color' while resolving lookups for '-fx-text-fill' from rule '*.button' in stylesheet jar:file:/C:/Program%20Files%20(x86)/Java/jdk1.7.0_06/jre/lib/jfxrt.jar!/com/sun/javafx/scene/control/skin/caspian/caspian.bss
WARNING: com.sun.javafx.css.StyleHelper calculateValue Could not resolve '-fx-shadow-highlight-color' while resolving lookups for '-fx-background-color' from rule '*.button' in stylesheet jar:file:/C:/Program%20Files%20(x86)/Java/jdk1.7.0_06/jre/lib/jfxrt.jar!/com/sun/javafx/scene/control/skin/caspian/caspian.bss
WARNING: com.sun.javafx.css.StyleHelper calculateValue Could not resolve '-fx-disabled-opacity' while resolving lookups for '-fx-opacity' from rule '*.button:disabled' in stylesheet jar:file:/C:/Program%20Files%20(x86)/Java/jdk1.7.0_06/jre/lib/jfxrt.jar!/com/sun/javafx/scene/control/skin/caspian/caspian.bss
WARNING: com.sun.javafx.css.StyleHelper calculateValue Could not resolve '-fx-text-base-color' while resolving lookups for '-fx-text-fill' from rule '*.button' in stylesheet jar:file:/C:/Program%20Files%20(x86)/Java/jdk1.7.0_06/jre/lib/jfxrt.jar!/com/sun/javafx/scene/control/skin/caspian/caspian.bss
WARNING: com.sun.javafx.css.StyleHelper calculateValue Could not resolve '-fx-shadow-highlight-color' while resolving lookups for '-fx-background-color' from rule '*.button' in stylesheet jar:file:/C:/Program%20Files%20(x86)/Java/jdk1.7.0_06/jre/lib/jfxrt.jar!/com/sun/javafx/scene/control/skin/caspian/caspian.bss
WARNING: com.sun.javafx.css.StyleHelper calculateValue Could not resolve '-fx-shadow-highlight-color' while resolving lookups for '-fx-background-color' from rule '*.text-field' in stylesheet jar:file:/C:/Program%20Files%20(x86)/Java/jdk1.7.0_06/jre/lib/jfxrt.jar!/com/sun/javafx/scene/control/skin/caspian/caspian.bss
WARNING: com.sun.javafx.css.StyleHelper calculateValue Could not resolve '-fx-text-inner-color' while resolving lookups for '-fx-text-fill' from rule '*.text-field' in stylesheet jar:file:/C:/Program%20Files%20(x86)/Java/jdk1.7.0_06/jre/lib/jfxrt.jar!/com/sun/javafx/scene/control/skin/caspian/caspian.bss
WARNING: com.sun.javafx.css.StyleHelper calculateValue Could not resolve '-fx-control-inner-background' while resolving lookups for '-fx-prompt-text-fill' from rule '*.text-field' in stylesheet jar:file:/C:/Program%20Files%20(x86)/Java/jdk1.7.0_06/jre/lib/jfxrt.jar!/com/sun/javafx/scene/control/skin/caspian/caspian.bss
WARNING: com.sun.javafx.css.StyleHelper calculateValue Could not resolve '-fx-accent' while resolving lookups for '-fx-highlight-fill' from rule '*.text-input' in stylesheet jar:file:/C:/Program%20Files%20(x86)/Java/jdk1.7.0_06/jre/lib/jfxrt.jar!/com/sun/javafx/scene/control/skin/caspian/caspian.bss
>
And my control does not display some styles correctly.
What's wrong?