I'm creating a cinema system, whereby the user should be able to select a film through a combobox in the Homepage. I have created an Array list in the FilmController Class and then converted it to an observableList and am struggling to populate its contents within the combobox (HomepageController).
This is the FilmController with the arraylist & observableList
public class FilmController {
private ArrayList<Film> films = new ArrayList<>();
public FilmController() {
Film f1 = new Film("Avatar", "James Cameron", "James Cameron",
"Sam Wortherington" + "Zoe Saldana", "162", "Sci-Fi", 8.50);
Film f2 = new Film("Black Panther", "Kevin Feige", "Ryan Coogler",
"Chadwick Boseman" + "Lupita Nyong'o", "135", "Sci-Fi Fantasy", 10.00);
Film f3 = new Film("Creed 2", "Sylvester Stallone", "Steven Caple Jr",
"Michael B Jordan" + "Tessa Thompson", "130", "Drama", 10.00);
Film f4 = new Film("Deadpool", "Simon Kinberg", "Tim Miller",
"Ryan Reynolds" + "Morena Baccarin", "109", "Sci-Fi", 7.50);
Film f5 = new Film("A Quiet Place", "Michel Bay", "John Krasinski",
"Emily Blunt" + "John Krasinski", "91", "Thriller", 8.00);
films.add(f1);
films.add(f2);
films.add(f3);
films.add(f4);
films.add(f5);
}
public ArrayList<Film> getFilms() {
return films;
}
public ObservableList<Film> getOlFilms() {
return FXCollections.observableArrayList(films);
}
}
I tried implementing this in the HomepageController, but it seem to be giving me an error:
public class HomepageController {
public ComboBox cbFilms;
public void initialize() {
cbFilms.setButtonCell((ListCell) cbFilms.getCellFactory().call(null));
}
public void cbListFilms(ActionEvent actionEvent) {
FilmController f = new FilmController();
cbFilms.setItems(f.getOlFilms().toArray());
}
}
I have looked at this question, however it doesn't seem to be working for me.
I'd like the combobox to list the film name only, and preferably when the mouse hovers over the film name I'd like it to display the remaining attributes if possible.
This is the fxml content for the combobox:
<ComboBox fx:id="cbFilms" layoutX="291.0" layoutY="138.0" onAction="#cbListFilms" prefHeight="31.0" prefWidth="230.0"
promptText="Please select film by name" style="-fx-background-color: tan;">
<items>
<FXCollections fx:factory="observableArrayList"/>
</items>
<effect>
<SepiaTone/>
</effect>
</ComboBox>