#Cannot add CSS file to my JavaFX scene

1 messages ยท Page 1 of 1 (latest)

merry perch
opaque hollowBOT
#

<@&987246399047479336> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question ๐Ÿค–. Maybe it helps! In any case, a human is on the way ๐Ÿ‘. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

To add a CSS file to your JavaFX scene, you need to follow these steps:

  1. Create a CSS file with the styles you want to apply to your JavaFX scene. Save this file with a .css extension.

  2. Add the CSS file to your JavaFX project's resources folder. You can do this by right-clicking on the resources folder in your project and selecting "New" -> "File" and then entering the name of your CSS file.

  3. In your Java code, load the CSS file and apply it to your scene by adding the following code:

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

Replace "your_css_file.css" with the name of your CSS file.

  1. Make sure that you have created a Scene object in your JavaFX application and set it as the scene for your primary stage.

By following these steps, you should be able to add a CSS file to your JavaFX scene successfully.

merry perch
#

i fixed it by moving my .css file to the same place as the .fxml files.. apparently .getResource() just doesn't like absolute file paths or any file path outside of the fxgroup folder

#

(i tried the exact same thing before and it didnt work, weird lol)