数组到 ComboBox - JavaFx

Array to ComboBox - JavaFx

我正在做一个学校项目,我试图将一个字符串数组直接放入组合框中,但出现错误。

错误:java:不兼容的类型:java.lang.String[] 无法转换为 javafx.collections.ObservableList

ComboBox comboDecks;
ComboBox comboTrucks;
ComboBox comboWheels;
private final String[] deckArray = {"The Master Thrasher -  ", "The Dictator - $ 45", "The Street King - $ 50"};
private final String[] trucksArray = {"7.75-inch axle -  ", "8-inch axle -  ", "8.5-inch axle -  "};
private final String[] wheelsArray = {"51mm - ", "55mm - ", "58mm - ", "61mm - "};


@Override
public void start(Stage stage) throws IOException {

    title1 = new Text("Skateboard Designer");
    title2 = new Text("Choose from the following Decks, Trucks, Wheels, and Accessories to design and price your own skateboard!");
    lblDecks = new Label("Decks: ");
    lblTrucks = new Label("Trucks: ");
    lblWheels = new Label("Wheels: ");
    lblAccess = new Label("Accessories: ");
    comboDecks = new ComboBox(deckArray);
    comboTrucks = new ComboBox(trucksArray);
    comboWheels = new ComboBox(wheelsArray);

ComBoBox 构造函数需要一个 ObservableList 作为参数。 如果要添加字符串数组,请使用 addAll() 方法

comboDecks = new ComboBox();
comboDecks.getItems.addAll(deckArray)
comboTrucks = new ComboBox();
comboTrucks .getItems.addAll(trucksArray)
comboWheels = new ComboBox();
comboWheels.getItems.addAll(wheelsArray)