1

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!

adsdf
  • 146
  • 1
  • 6
  • How can you write a custom `Control` without a Skin? Just mix everything into a single class? This is surely not what the JavaFX developers had in mind.. – eckig Jan 30 '15 at 08:08
  • I just started with JavaFX 2 days ago and just need it for a very specific task. I know this is probably not best practice, but yes, everything is mixed in this one class and showing on screen as intended. So it can't be that wrong I suppose :) – adsdf Jan 30 '15 at 08:20

1 Answers1

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?

Community
  • 1
  • 1
Puce
  • 37,247
  • 13
  • 80
  • 152
  • Thanks for your answer! The thing is that I'm not using stylesheets and there is no css file to reference. As I also don't have a `Skin` class (because I don't think / hope I need it) I don't know what to return in createDefaultSkin(). eckig is probably right to say that my way isn't politically correct, but it's working as it is and I really just need a simple way to avoid the error message that Java declares as "severe" (although the application isn't crashing). – adsdf Jan 30 '15 at 13:30
  • That did the trick, thank you so much :) I ended up extending `Pane` class and now the error is gone. Thanks! – adsdf Feb 02 '15 at 07:39