0

I added .css stylesheet to Scene builder for Choice box, but relative path is wrong:

INFO: Could not find stylesheet: file:/mnt/windows/projects/Java/DiamondCircle/out/production/DiamondCircle/gui/choicebox.css

It clearly doesn't exist. Why does it look for path in out/production/? I use IntelliJ and System.out.println(getClass().getResource("entry.fxml").toString()); returns:

file:/mnt/windows/projects/Java/DiamondCircle/out/production/DiamondCircle/gui/entry.fxml

Folder hierarchy

When I choose absolute path in Scene builder it works, but I don't want to use absolute path.

qu4lizz
  • 317
  • 2
  • 12
  • Your image doesn't show the contents of `out/production/DiamondCircle/gui`, and so doesn't prove if it's there or not. It _should_ be there, as the `out` directory is the build output (i.e., where compiled classes and processed resources go). The `src` directory is just that—the directory for sources.; that directory does not end up on the class-path. – Slaw Aug 05 '22 at 19:15
  • That path does exist, but that's not the path I set. When I put `.css` file there I get `INFO: Could not find stylesheet: file:/mnt/windows/projects/Java/DiamondCircle/out/production/DiamondCircle/out/production/DiamondCircle/gui/choicebox.css`. The problem is that `/out/production` is starting directory and not `/DiamondCircle/`. – qu4lizz Aug 06 '22 at 07:43
  • Where do you add the stylesheet? In code (i.e., with `Class#getResource(String)`)? Or in the FXML file (i.e., `stylesheet="..."`)? Can you provide a [mre]? – Slaw Aug 06 '22 at 07:46
  • I tried both, but currently I use Scene builder to specify stylesheet, so it's in FXML file. As I said it works with absolute path, but not with relative. – qu4lizz Aug 06 '22 at 08:28
  • If you've tried `Class#getResource(String)`, and that method _did not_ return `null`, then the resource was being found. If it was returning `null`, then double-check you're using the correct _resource_ path, and then double-check that your resource is being included in the build output. If you're using Scene Builder to set the stylesheet, and it's using the absolute path, then try changing it to the relative path. Possibly using `@relative/path/to/stylesheet.css`. See https://openjfx.io/javadoc/18/javafx.fxml/javafx/fxml/doc-files/introduction_to_fxml.html#location_resolution – Slaw Aug 08 '22 at 07:42
  • And for general information on resources in JavaFX and potential debugging techniques, see [How do I determine the correct path for FXML files, CSS files, Images, and other resources needed by my JavaFX Application?](https://stackoverflow.com/q/61531317/6395627). – Slaw Aug 08 '22 at 07:43

0 Answers0