问题
Dear Stackoverflow community,
I've implemented a custom control in JavaFX extending Control
class.
Everything is just working fine, but I keep getting the error message
Jan 30, 2015 8:33:31 AM javafx.scene.control.Control impl_processCSS
SEVERE: The -fx-skin property has not been defined in CSS for
CustomView@19e4d42 and createDefaultSkin() returned null.
when I run the application.
I read a lot about SkinBase
and BehaviorBase
, but since everything is working as it is supposed to, I would just like this error to disappear without implementing these classes if possible.
I'm not using CSS and I can't find any method to manually set a default skin.
I would really appreciate your help. Thanks in advance!
回答1:
Since JavaFX 8 (comes with Java SE 8), there is the method createDefaultSkin()-method, which you can (should?) override in a custom control.
Furthermore I recommend to call the following statement in the constructor of your custom control:
getStyleClass().setAll("my-custom-control");
Then override the method getUserAgentStylesheet() and in the referenced css file add:
.my-custom-control {
-fx-skin: "mypackage.impl.skin.MyCustomControlSkin";
}
where this reference class is the default skin of your custom control.
But as the documentation and error message explains, it's also ok to just override the mentioned method or just to provide the css.
If you don't need a skinnable control but just want to create a custom control which is composed of other controls then I suggest to write a fx:root based control instead of extending Control. Also have a look at my following answer: Should we use FXML in JavaFX custom controls or not?
来源:https://stackoverflow.com/questions/28231654/createdefaultskin-returned-null-error-in-javafx-custom-control