Issue
I am currently working on a stock management system. I am receiving the following error when changing scenes on the application. Error is displayed only if that screen contains a combo box which are most of the screens as seen in the images below.
Everything runs and works fine but I get the error below. I believe it is to do with the CSS combobox styling in CSS.
Background of previous error in relation to CSS: Initially I was having trouble with the files locating the CSS and was getting the error null/styles.css. Which I manged resolve by changing the following stylesheets="@style.css"
to stylesheets="/stock/style.css"
. Not sure if this affects anything I thought I would mention it in case it is something to do with this even though the error was still showing before the changes.
May 19, 2020 6:31:50 PM javafx.scene.control.Control loadSkinClass
SEVERE: No valid constructor defined in 'com.sun.javafx.scene.control.skin.ComboBoxBaseSkin' for control ComboBox[id=comboStatus, styleClass=combo-box-base combo-box].
You must provide a constructor that accepts a single Skinnable (e.g. Control or PopupControl) parameter in com.sun.javafx.scene.control.skin.ComboBoxBaseSkin.
The CSS is as per the following:
.combo-box .list-cell {
-fx-background: #2D75E8;
-fx-background-color: transparent;
-fx-text-fill: white;
-fx-padding: 3 0 2 7;
-fx-cell-size: 1.96667em;
-fx-font-weight: bold;
}
.combo-box .list-view .list-cell {
-fx-text-fill: white;
-fx-font-weight: bold;
}
.combo-box-popup .list-view {
-fx-background-color: #2D75E8, #2D75E8;
-fx-background-insets: 0, 1;
-fx-effect: dropshadow(three-pass-box, rgba(0, 0, 0, 0.6), 8, 0.0, 0, 0);
-fx-font-weight: bold;
}
.combo-box-popup .list-view .list-cell {
-fx-padding: 4 0 4 5;
-fx-font-weight: bold;
/* No alternate highlighting */
-fx-background-color: #2D75E8;
}
.combo-box-popup .list-view .list-cell:filled:selected, .combo-box-popup .list-view .list-cell:filled:selected:hover {
-fx-background: -fx-accent;
-fx-background-color: -fx-selection-bar;
-fx-text-fill: white;
}
.combo-box-popup .list-view .list-cell:filled:hover {
-fx-background-color: #2D75E8;
-fx-text-fill: white;
-fx-font-weight: bold;
}
.combo-box-base {
-fx-skin: "com.sun.javafx.scene.control.skin.ComboBoxBaseSkin";
-fx-background-color: #2D75E8, #2D75E8, #2D75E8, #2D75E8;
-fx-background-radius: 5, 5, 4, 3;
-fx-background-insets: 0 0 -1 0, 0, 1, 2;
-fx-padding: 0;
-fx-font-weight: bold;
}
.combo-box-base:hover {
-fx-color: -fx-hover-base;
}
.combo-box-base:showing {
-fx-color: -fx-pressed-base;
}
I am also getting a CSS parsing error on some of the screens as seen below:
May 19, 2020 7:08:55 PM com.sun.javafx.css.parser.CSSParser declaration
WARNING: CSS Error parsing '*{-fx-text-inner-color: #3f5cc3; -fx-font-weight: 15px;}: Expected '<font-weight>' while parsing '-fx-font-weight' at [1,50]
I don't quite understand how it wants me to format it even though the error is showing the expected. Why does it need to be '<font-weight>'
?
Here is are some screenshots of the application itself:
Solution
You have:
.combo-box-base {
-fx-skin: "com.sun.javafx.scene.control.skin.ComboBoxBaseSkin";
-fx-background-color: #2D75E8, #2D75E8, #2D75E8, #2D75E8;
-fx-background-radius: 5, 5, 4, 3;
-fx-background-insets: 0 0 -1 0, 0, 1, 2;
-fx-padding: 0;
-fx-font-weight: bold;
}
Which is the source of your error. Specifically:
-fx-skin: "com.sun.javafx.scene.control.skin.ComboBoxBaseSkin";
This is telling JavaFX to use the specified class as the Skin
implementation used for all controls which have the .combo-box-base
style class. The purpose of this property is to override the default skin of a Control
with a custom-made one. Using custom skins is how one can change the look-and-feel of a JavaFX application. However, your CSS specifies ComboBoxBaseSkin
which is strange for at least three reasons:
- It's an abstract class and thus can't be used directly.
- It's the direct superclass of
ComboBox
's default skin:ComboBoxPopupControl
. - It's an internal class (i.e. private API). You should not depend on internal API directly as it can change without notice. Case in point, the default skins became public API in JavaFX 9 and moved to a different package; this would have broken your application if it worked in the first place.
And ultimately the error comes from the fact ComboBoxBaseSkin
has a constructor with a ComboBoxBase
parameter, not a ComboBox
parameter (CSS appears to look for an exact match).
The solution, it would appear, is to simply remove the -fx-skin
property from your CSS and just let ComboBox
use its default skin. Or, if you're actually trying to use a custom skin, use the fully qualified name of your custom skin class as the value instead.
As for your parsing error, -fx-font-weight
expects the value to be a weight, as already noted by @James_D in the question comments. If you want to change the size use -fx-font-size
. You can check out the JavaFX CSS Reference Guide to learn more about JavaFX-CSS.
Answered By - Slaw
Answer Checked By - Mary Flores (JavaFixing Volunteer)