Jonatan Stenbacka Jonatan Stenbacka - 1 month ago 6
Java Question

How to reset back to default css after adding style?

Basically I have changed the css for a text field in javafx by adding a style class like this:

textfield.getStyleClass().add("textfieldstyle");


But then I want to be able to revert it back to its original appearance. But since the original appearance in this case is the default skin for JavaFX, I can't find the original layout for the textfields. I found the textfieldskin properties here, but its a jungle, and I can't find anything about the color of the -fx-control-inner-background, -fx-text-box-border and -fx-focus-color, which is what I want to know.

I've tried
textfield.getStyleClass().remove("textfieldstyle");
and think that does remove the new css, but it doesn't apply the old one again.

Answer

Thanks to the comments by @UlukBiy and @varren I solved the issue. System.out.println(textfield.getStyleClass()); was of great use since it allowed me to check which style classes were applied on the text field as default. And as pointed out in the comments those where text-input and text-field.

So to restore the text field css to its default value I just did:

textfield.getStyleClass().clear();
textfield.getStyleClass.addAll("text-field", "text-input");
Comments