beastlyCoder
beastlyCoder

Reputation: 2401

JavaFX Scene Builder Styling

Could someone give me some tips on how to style my JavaFx Application. I am using scene builder to put my app together. Would I have to import css files into my javafx project. An explanation on this would be greatly appreciated :)

Upvotes: 0

Views: 1315

Answers (1)

Bo Halim
Bo Halim

Reputation: 1776

You have two ways to do this, (from the SceneBuilder/inside the FXML) or the Java Code :

//Java Code :
root.getStylesheets().add(getClass().getResource("style.css").toExternalForm());

For the scenebuilder you use a relative path to the location of your file.css and assign to each graphical element (node) its (Id/StyleClass) in the properties section of the SceneBuilder. The Id is marked by # sign example :

#styleID{
  -fx-background-color:red;
}

Upvotes: 3

Related Questions