如何将可观察列表绑定到组合框?

时间:2019-03-15 20:11:44

标签: javafx java-8

如何在可观察到的位置将olfilmtitles放入名为filmcombobox的组合框中。这样我就可以使用对象的所有其他属性。因此,如果我要添加另一部电影,它将自动将其及其值自动添加到组合框中。

public class FilmsController implements Initializable {
    private ArrayList<String> filmtitles = new ArrayList<>();
    private ArrayList<Films> films = new ArrayList<>();

    public Button startbutton;
    public Button drinksButton;
    public Button backtohomebutton;
    @FXML
    public TextField totalprice;
    public Button receiptbutton;
    @FXML
    public ComboBox<String> filmcombobox;
    @FXML
    private Button leavepagebutton;

    ObservableList<String> olfilmtitles = FXCollections.observableArrayList(filmtitles);

    public FilmsController() {
        Films matrix = new Films("Matrix", 5, 15, 120, "2:30");
        films.add(matrix);
        filmtitles.add(matrix.getName());

    }

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        filmcombobox.setItems(olfilmtitles);

    }
}

0 个答案:

没有答案