Search This Blog

JavaFX: load css from file

  • load from relative path:
     // the java class is in the same directory as the .css file.
    String css = getClass().getResource("MyApp.css").toExternalForm();
    scene.getStyleSheets().add(css);
    
  • load from absolute path:
    // the .css file is stored under <ROOT>/css/ directory.
    String css = getClass().getResource("css/MyApp.css").toExternalForm(); 
    scene.getStyleSheets().add(css);
    

No comments:

Post a Comment