Loading new fxml in the same scene

Why your code does not work The loader creates a new AnchorPane, but you never add the new pane to a parent in the scene graph. Quick Fix Instead of: content = (AnchorPane) FXMLLoader.load(“vista2.fxml”); Write: content.getChildren().setAll(FXMLLoader.load(“vista2.fxml”)); Replacing the content children with your new vista. The content itself remains in the scene graph, so when you … Read more

Javafx tableview not showing data in all columns

This question is really a duplicate of: Javafx PropertyValueFactory not populating Tableview, but I’ll specifically address your specific case, so it’s clear. Suggested solution (use a Lambda, not a PropertyValueFactory) Instead of: aColumn.setCellValueFactory(new PropertyValueFactory<Appointment,LocalDate>(“date”)); Write: aColumn.setCellValueFactory(cellData -> cellData.getValue().dateProperty()); For more information, see this answer: Java: setCellValuefactory; Lambda vs. PropertyValueFactory; advantages/disadvantages How do you use a … Read more

JavaFX periodic background task

You can use Timeline for that task: Timeline fiveSecondsWonder = new Timeline( new KeyFrame(Duration.seconds(5), new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println(“this is called every 5 seconds on UI thread”); } })); fiveSecondsWonder.setCycleCount(Timeline.INDEFINITE); fiveSecondsWonder.play(); for the background processes (which don’t do anything to the UI) you can use old good java.util.Timer: new Timer().schedule( … Read more

How do I determine the correct path for FXML files, CSS files, Images, and other resources needed by my JavaFX Application?

Short version of answer: Use getClass().getResource(…) or SomeOtherClass.class.getResource(…) to create a URL to the resource Pass either an absolute path (with a leading /) or a relative path (without a leading /) to the getResource(…) method. The path is the package containing the resource, with . replaced with /. Do not use .. in the … Read more