I need to load JavaFX TreeView data at application startup. The problem is node lookup() method always return null.
CODE
public class Main extends Application {
public static final String APPLICATION_NAME = "testapp" ;
public static void main(String args[]) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
String fxml = "/fxml/main-window.fxml";
String globalCss = "/styles/main.css";
FXMLLoader loader = new FXMLLoader(getClass().getResource(fxml));
Parent root = (Parent) loader.load();
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.getScene().getStylesheets().add(globalCss);
primaryStage.setMaximized(true);
TreeView treevw = (TreeView) scene.lookup("#treevw");
// lazy init here
primaryStage.show();
}
}
FXML
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
i've found this solution but it doesn't work for me (both).
Can anybody please help to solve the issue?