JavaFX style class won't refresh

前端 未结 5 1108
说谎
说谎 2021-02-08 05:08

I\'m adding a style class to an node if it\'s selected and then remove it if I select other item. Even if I remove the style class the style wont refresh so it wont go back to n

5条回答
  •  情深已故
    2021-02-08 05:52

    You can try to add a css for the application instead. You can use even FXML to separate de design from the logic of your application. Here is a piece of code that worked for me in JavaFX 2.1!

    private Parent replaceSceneContent(String fxml) throws Exception {
       Parent page = (Parent)
          FXMLLoader.load(
             Main.class.getResource(fxml), null, new JavaFXBuilderFactory());
       Scene scene = stage.getScene();
       if (scene == null) {
          scene = new Scene(page, 1366, 720);
          scene.getStylesheets().add(
             Main.class.getResource(
                "../skinFolder/css/defaultSkin.css" ).toExternalForm());
          stage.setScene(scene);
       } else {
          stage.getScene().setRoot(page);
       }
       stage.sizeToScene();
       return page;
    }
    

提交回复
热议问题