Java FX TableView无法显示数据

时间:2017-11-18 21:35:25

标签: java javafx-8

我已经在这里查看了类似的问题(例如,Javafx PropertyValueFactory not populating Tableview)并仔细检查了我是不是只是拼写/大写错误。情况似乎并非如此。我观察到的行为是我的TableView反映了底层模型的变化 - 行被添加 - 但没有一个单元实际上正在绘制他们的数据。

这是数据对象类:

public class HistoryEntry {
private SimpleIntegerProperty _gameNumber = new SimpleIntegerProperty();
private SimpleStringProperty _playerOneMove = new SimpleStringProperty();
private SimpleStringProperty _playerTwoMove = new SimpleStringProperty();

public HistoryEntry(int gameNumber, String p1Move, String p2Move) {
    _gameNumber.set(gameNumber);
    _playerOneMove.set(p1Move);
    _playerTwoMove.set(p2Move);
}

Integer getGameNumber() {
    return Integer.valueOf(_gameNumber.get());
}

String getPlayerOneMove() {
    return _playerOneMove.get();
}

String getPlayerTwoMove() {
    return _playerTwoMove.get();
}
}

这是控制器,设置TableView:

...
private ObservableList<HistoryEntry> _historyList;
@FXML private TableView<HistoryEntry> _history;
@FXML private TableColumn<HistoryEntry, Integer> _gameNumber;
@FXML private TableColumn<HistoryEntry, String> _playerMove;
@FXML private TableColumn<HistoryEntry, String> _opponentMove;
@FXML private Button _debugHEButton;
...
    @Override
    public void initialize(URL location, ResourceBundle resources) {
        _historyList = FXCollections.observableList(new ArrayList<>());
        _history.setItems(_historyList);
        _gameNumber.setCellValueFactory(new PropertyValueFactory<>("GameNumber"));
        _playerMove.setCellValueFactory(new PropertyValueFactory<>("PlayerOneMove"));
        _opponentMove.setCellValueFactory(new PropertyValueFactory<>("PlayerTwoMove"));
    }
...
    public void handleDebugHE(ActionEvent actionEvent) {
        int row = _historyList.size() + 1;
        _historyList.add(new HistoryEntry(row, "BOGUS 1", "BOGUS 2"));
    }

0 个答案:

没有答案