在javafx中,可以使用cellfactory来进行赋初值
下面我将举例进行说明
首先当对应的fxml文件被调用时,他里面的相对应的controller中的intiablize方法将被自动调用,
@FXML
private void initialize() {
// Initialize the person table with the two columns.
firstNameColumn.setCellValueFactory(
cellData -> cellData.getValue().firstNameProperty());
lastNameColumn.setCellValueFactory(
cellData -> cellData.getValue().lastNameProperty());
// Clear person details.
showPersonDetails(null);
// Listen for selection changes and show the person details when changed.
personTable.getSelectionModel().selectedItemProperty().addListener(
(observable, oldValue, newValue) -> showPersonDetails(newValue));
}
需要添加@Fxml以让程序能识别。
其中的cellData是我们同过mainAPP把值