How to pick up selected item from a javafx Combobox

Asked

Viewed 1,961 times

1

How can I pick up the selected item from a Combobox?

I saw some ways to do but I couldn’t implement, I don’t understand how it works.

I can set the items of the combobox as follows:

 ObservableList<String> options
                = FXCollections.observableArrayList(
                        "Ativo",
                        "Suspenso"

                );
        cbStatus.setItems(options);

just need to be able to catch them when I select them in the combobox.

  • 1

    Your question is incomplete... "I’ve tried some things" or saying "javafx is more boring than swing" doesn’t help much... BTW http://www.java2s.com/Code/JavaFX/SetandgetvalueforComboBox.htm or this http://www.java2s.com/Tutorials/Java/JavaFX/0590__JavaFX_ComboBox.htm to see if it helps...

  • I tried to use getValue but it didn’t work

  • 1

    Problem solved, I created a Mousecliked event and I can get the value inside that event. Thank you

  • 1

    Much better now your question, my +1... and I’m glad I got it.

1 answer

1

Depending on whether you want to use the property or the value directly is different.

//por valor
cbStatus.getValue();
cbStatus.valueProperty().get();

//bind com a propriedade
statusProperty.bind(cbStatus.valueProperty());

Browser other questions tagged

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