How to get selected item from a ComboBox in javaFx

1

How can I get the selected item from a ComboBox?

I saw some ways to do but I could not implement, that is, I did not understand how it works.

I can set the items in the comboBox as follows:

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

                );
        cbStatus.setItems(options);

I just can not get them when I select them in the comboBox.

    
asked by anonymous 18.06.2015 / 13:48

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());
    
23.08.2015 / 07:42