Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a stylesheet dynamically and add that to a node [closed]

Tags:

css

javafx

Currently JavaFX does not allow attaching a stylesheet to a node (or scene) that is not in the classpath. So, if a css file is not in the classpath already, it cannot be added to any node. The getStyleSheets().add() method will state 'WARNING Resource [your file] not found'. So is there any workaround to this limitation?

like image 478
Amir Mousavi Avatar asked Sep 17 '25 16:09

Amir Mousavi


1 Answers

Not sure if this is what you are looking for...

Button node = new Button();
node.getStyleClass().add("my-new-style-class");

.my-new-style-class {
    -fx-padding: 5;
}
like image 145
Jai Avatar answered Sep 19 '25 08:09

Jai