带有复选框的用户界面Java Fxml表视图
我正在尝试使用复选框创建表视图。 由于某些原因,“initialize”方法没有运行。 当我运行代码时,该表将显示,其中没有字段。未打印打印消息“TEST”。 有人能帮我弄清楚吗
public class Main extends Application {
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("AddTransactionsToBlock.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
public class AddTransactionsToBlockController implements Initializable {
@FXML
private TableColumn<TableSetterGetter, String> name;
@FXML
private TableColumn<TableSetterGetter, Integer> id;
@FXML
private TableColumn<TableSetterGetter, CheckBox> select;
@FXML
private TableView<TableSetterGetter> tableView;
ObservableList <TableSetterGetter> list = FXCollections.observableArrayList();
@Override
public void initialize(URL url, ResourceBundle rb) {
System.out.println("TEST PRINT");
for (int i = 0; i < 10; i++) {
CheckBox ch = new CheckBox("" + i);
list.add(new TableSetterGetter(i, "HELLO", ch));
}
tableView.setItems(list);
id.setCellValueFactory(new PropertyValueFactory<TableSetterGetter, Integer>("id"));
name.setCellValueFactory(new PropertyValueFactory<TableSetterGetter, String>("name"));
select.setCellValueFactory(new PropertyValueFactory<TableSetterGetter, CheckBox>("checkBox"));
}
}
共 (0) 个答案