1

I need to add the file style.css as stylesheet to a scene. I am trying to do this inside the class ScreenController which is in the package justAnotherChessGame.model. The file is in the same directory but in a different package. How can I find the relative path? Project structure

Flavio
  • 61
  • 10

2 Answers2

0

Use Class.getResource to access files bundled in an application:

scene.getStylesheets().add(MainView.class.getResource("style.css").toString());

You will need to import MainView so the compiler recognizes its name.

VGR
  • 40,506
  • 4
  • 48
  • 63
0

If your scene is sc and pane is p in ScreenController,

Scene sc = new Scene(p, 400, 300);
sc.getStylesheets().add("/justAnotherChessGame/view/style.css");
primaryStage.setScene(sc);

You need to study about this case.

Panduka Nandara
  • 504
  • 6
  • 14