带复选框的Java Fxml表视图

时间:2019-01-04 10:59:27

标签: java user-interface javafx checkbox

我正在尝试创建带有复选框的表格视图。 由于某种原因,“初始化”方法无法运行。 当我运行代码时,该表将显示其中没有字段的字段。未打印打印消息“ 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 个答案:

没有答案