javaFX FXML 下拉框/选择框/choicebox 的 填充以及用enum/枚举填充 用法

1.普通地加载

<Label layoutX="18.0" layoutY="164.0" text="性别" />
<ChoiceBox fx:id="outBhEncodingCbx" layoutX="139.0" layoutY="160.0" prefWidth="150.0">
    <items>
        <FXCollections fx:factory="observableArrayList">
            <String fx:value="male" />
            <String fx:value="female" />
            <String fx:value="unknown" />
        </FXCollections>
    </items>
</ChoiceBox>

2.通过FXCollections.observableArrayList

public class Main extends Application {
  ObservableList cursors = FXCollections.observableArrayList(
      Cursor.DEFAULT,
      Cursor.CROSSHAIR,
      Cursor.WAIT,
      Cursor.TEXT,
      Cursor.HAND,
      Cursor.MOVE,
      Cursor.N_RESIZE,
      Cursor.NE_RESIZE,
      Cursor.E_RESIZE,
      Cursor.SE_RESIZE,
      Cursor.S_RESIZE,
      Cursor.SW_RESIZE,
      Cursor.W_RESIZE,
      Cursor.NW_RESIZE,
      Cursor.NONE
    ); 
    @Override
    public void start(Stage stage) {
      ChoiceBox choiceBoxRef = ChoiceBoxBuilder.create()
          .items(cursors)
          .build();
          ......

3.使用enum类枚举自动填充
需要在这个fxml的controller的初始化里使用:

public void initialize(URL location, ResourceBundle resources) {
        gender.getItems().addAll(GenderType.values());//使用enum类型加载到choice box,此处枚举类为GenderType
    }

1参考:FXML(JavaFX8.0)中choicebox的子元素追加写法
2来自:Java选择框
3.来自:stackoverflow