Populate Choicebox defined in FXML

后端 未结 2 1849
长情又很酷
长情又很酷 2020-12-11 07:26

I\'m learning javaFX and my problem is that I have simple window with some choicebox and button. This window is defined via FXML which is also associated wi

2条回答
  •  甜味超标
    2020-12-11 07:56

    @using FXML STEP 1: Add a choice box in the scene builder and call it maybe(choiceBox) STEP 2: IN the controller add the following codes @FXML private ChoiceBox choiceBox ;

    @Override
    public void initialize(URL url, ResourceBundle rb) {
     ObservableList list = FXCollections.observableArrayList();
       list.addAll("choice1", "choice2","choice3");
      //populate the Choicebox;  
      choiceBox .setItems(list);
    
    }
    

提交回复
热议问题