可以(Javafx)我使用ComboBox项目来显示页面吗?我需要将filmCombo组合框中的每个选项链接到fxml文件

问题描述 投票:0回答:1

我需要将电影组合中的每个选项链接到fxml文件,当我点击电影组合中的不同选项时,我需要时间组合中的选项进行更改。

@FXML
public ComboBox<String> filmCombo = new ComboBox<String>();
 ObservableList film = FXCollections.observableArrayList("Movie 1", "Movie 2", "Movie 3", "Movie 4", "Movie 5", "Movie 6", "Movie 7", "Movie 8", "Movie 9", "Movie 10");
//Listen for selection changes

@FXML
public ComboBox<String> timeCombo;
ObservableList time = FXCollections.observableArrayList("1:15", "4:15", "7:15");

@Override
public void initialize(URL location, ResourceBundle resources) {
    filmCombo.setValue("Movie 1");
    filmCombo.setVisibleRowCount(4);


    timeCombo.setItems(time);
    filmCombo.setItems(film);

    filmCombo.getSelectionModel().selectedItemProperty().addListener( (v, oldValue, newValue)  -> System.out.println(newValue));
    timeCombo.getSelectionModel().selectedItemProperty().addListener( (v, oldValue, newValue)  -> System.out.println(newValue));
}
javafx combobox scenebuilder
1个回答
0
投票

ComboBox像按钮一样有OnAction。

filmCombo.setOnAction((ActionEvent event) -> {
        String movieSelected = filmCombo.getValue().toString();
        if (movieSelected.equals("movie 1")) {//or use a switch statement
            time.addAll("time 1", "time 2");//set the items in the list for the time comboBox
            //add any other actions
            showRelevantScreen();//show another screen if needed
        }
    });
© www.soinside.com 2019 - 2024. All rights reserved.