0

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

3
  • I've tried your CSS, and I don't get that error... Are you sure you're running what you think you're running...? Commented Mar 19, 2017 at 4:58
  • How do you mean? When I run it I press the play button (in eclipse). This project is the only one I have open. I run the program as a Java application and the view that pops up is the homepage. I click "Login" button to open login view. I'm expecting the background to be black but it's not. Not sure what I'm doing wrong? :/ Commented Mar 19, 2017 at 5:25
  • Oh I just realised I'm getting the warning in console that reads "WARNING: Resource css/styles.css not found". So it must be somehow related to the file path? Added some edits above. Commented Mar 19, 2017 at 5:27

1 Answer 1

6

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());
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.