Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset back to default css after adding style?

Tags:

java

javafx

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 triedtextfield.getStyleClass().remove("textfieldstyle"); and think that does remove the new css, but it doesn't apply the old one again.

like image 537
Jonatan Stenbacka Avatar asked Jun 10 '15 14:06

Jonatan Stenbacka


People also ask

How do I Reset CSS to default?

Use the inherit keyword to make an element's property the same as its parent. Use the revert keyword to reset a property to the value established by the user-agent stylesheet (or by user styles, if any exist). Use the revert-layer keyword to reset a property to the value established in a previous cascade layer.

How do you undo CSS?

So if this was the first change you made, then all you'll need to do is select all the CSS in the main editor, then hit backspace to delete it and finally save to save the changes.


1 Answers

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 it is pointed out in the comments those where text-input and text-field.

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

textfield.getStyleClass().clear();
textfield.getStyleClass().addAll("text-field", "text-input");
like image 144
Jonatan Stenbacka Avatar answered Oct 13 '22 00:10

Jonatan Stenbacka