xeno7
xeno7

Reputation: 115

JavaFX css styles not working - Unknown property + Resource not found

I am getting the warning "Unknown property" for the following code, located in my css/styles.css file:

.root {
    -fx-background-color: #000000;
}

I do have jfxrt.jar in my JRE System Library, and JavaFX works fine otherwise.

When I run the program, the custom style does not appear at all on the view I am trying to apply it to.

The following is in the view file:

Scene scene = new Scene(pane);
scene.getStylesheets().add("css/styles.css");
stage.setScene(scene);

EDIT:

I am getting the following warning in the console:

WARNING: Resource "css/styles.css" not found.

The path for the css file is: View/css/styles.css

Path for login view is View/LoginView.java

Upvotes: 0

Views: 5239

Answers (1)

xeno7
xeno7

Reputation: 115

I figured it out. I just needed to change

scene.getStylesheets().add("css/styles.css");

to

scene.getStylesheets().add(getClass().getResource("css/styles.css").toExternalForm());

Upvotes: 5

Related Questions