我正在尝试将数据放入表格视图中,该视图是我在场景构建器上为电影院预订系统的FXML创建的,但是当我使用此代码时,没有数据添加到表格中,我想知道自己做错了什么。我遵循了教程,但没有任何效果。
这是我正在使用的代码 有什么我可以添加使其起作用的吗?
public class FilmTableController implements Initializable{
//
@FXML private TableView<Film> tableView;
@FXML private TableColumn<Film, String> filmTitleColumn;
@FXML private TableColumn<Film, LocalDate> DateColumn;
@FXML private TableColumn<Film, LocalTime> ScreeningTime;
@FXML private TableColumn<Film, Integer> TotalSeats;
@FXML private TableColumn<Film, Integer> AvaliableSeats;
@FXML private TableColumn<Film, Integer> BookedSeats;
@FXML private TableColumn<Film, Currency> Price;
@FXML private TableColumn<Film, String> Age;
@Override
public void initialize(URL locations, ResourceBundle resources) {
filmTitleColumn.setCellValueFactory(new PropertyValueFactory<Film, String>("filmTitle"));
DateColumn.setCellValueFactory(new PropertyValueFactory<Film, LocalDate>("Date"));
ScreeningTime.setCellValueFactory(new PropertyValueFactory<Film, LocalTime>("Screening Time"));
TotalSeats.setCellValueFactory(new PropertyValueFactory<Film, Integer>("TotalSeats"));
AvaliableSeats.setCellValueFactory(new PropertyValueFactory<Film, Integer>("AvaliableSeats"));
BookedSeats.setCellValueFactory(new PropertyValueFactory<Film, Integer>("BookedSeats"));
Price.setCellValueFactory(new PropertyValueFactory<Film, Currency>("price"));
Age.setCellValueFactory(new PropertyValueFactory<Film, String>("age"));
ObservableList list = getFilms();
tableView.setItems(getFilms());
tableView.getColumns().addAll(filmTitleColumn, DateColumn, ScreeningTime, TotalSeats, AvaliableSeats, BookedSeats, Price, Age);
tableView.setEditable(true);
filmTitleColumn.setCellFactory(TextFieldTableCell.forTableColumn());
tableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
tableView.setVisible(false);
}
public ObservableList getFilms() {
Film film1 = new Film("Captain Marvel", LocalDate.of(2019, Month.MARCH,12), LocalTime.of(12, 00), 50, 45, 5, 12.00, "18");
ObservableList list = FXCollections.observableArrayList(film1);
return list;
}
}