JavaFX – Filtered ComboBox

As far as the filtering of the drop down is concerned. Isn’t wrapping the list of possible options in a FilteredList the best solution? MCVE: import javafx.application.Application; import javafx.application.Platform; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.collections.transformation.FilteredList; import javafx.scene.Scene; import javafx.scene.control.ComboBox; import javafx.scene.control.TextField; import javafx.scene.layout.HBox; import javafx.stage.Stage; public class MCVE extends Application { public void start(Stage stage) … Read more

How do you use a JavaFX TableView with java records?

Solution Use a lambda cell value factory instead of a PropertyValueFactory. For some explanation of the difference between the two, see: Java: setCellValuefactory; Lambda vs. PropertyValueFactory; advantages/disadvantages Why this works The issue, as you note, is that record accessors don’t follow standard java bean property naming conventions, which is what the PropertyValueFactory expects. For example, … Read more

How to use PauseTransition method in JavaFX?

How to use a PauseTransition A PauseTransition is for a one off pause. The following sample will update the text of a label after a one second pause: label.setText(“Started”); PauseTransition pause = new PauseTransition(Duration.seconds(1)); pause.setOnFinished(event -> label.setText(“Finished: 1 second elapsed”); ); pause.play(); Why a PauseTransition may not be the best answer for you According to … Read more

FXMLLoader getController returns NULL?

Change this @FXML public void editPerson() { try { FXMLLoader loader = new FXMLLoader(getClass().getResource( “PersonEditor.fxml”)); PersonEditorCtrl ctrl = loader.getController(); ctrl.init(table.getSelectionModel().getSelectedItem()); Parent root = (Parent) loader.load(); Scene newScene = new Scene(root); Stage newStage = new Stage(); newStage.setScene(newScene); newStage.show(); } catch (Exception e) { e.printStackTrace(); } } To that: @FXML public void editPerson() { try { FXMLLoader … Read more