Addall items in combobox

Asked

Viewed 183 times

-1

I have a ComboBox, and I am trying to put items (string values) but it is not accepting.

I did it this way:

private ComboBox<?> meuCombo;

public void combos() {
    meuCombo.getItems().addAll("A", "B");
}

1 answer

0


Note that the method getItems() of the combobox returns a Observablelist. Why don’t you try manually setting the Observablelist of your Combobox, thus:

private ComboBox<String> meuCombo;

public void combos(){
    ObservableList<String> itens = FXCollections.observableArrayList();
    itens.addAll("A", "B");

    meuCombo.setItems(list)
}

I didn’t see in your code how you urged your Combobox but you can pass the Observablelist as an argument in that way: meuCombo = new ComboBox(itens).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.