How to show a value of a ComboBox in javafx by passing a value?

0

friends I'm doing an application in javafx which has to perform the CRUD operations, now I have a combobox with the name typedocumento, now I capture the information and I keep everything well, when updating the data I could not make the combobox show me the desired value Well that's how I fill the combobox

TipoDocumentos.getItems().addAll(
            "Cedula de ciudadania",
            "Tarjeta de identidad",
            "Pasaporte",
            "Cedula de extranjeria"
    );

and that's how I capture the information

String documen = (String) TipoDocumentos.getValue();

Well, I'm new to javafx

    
asked by Jhonny Luis 21.10.2017 в 07:49
source

1 answer

1

You have to work with the SelectionModel of the ComboBox. For example, to select any item (let's say for example "Passport") you should do:

TipoDocumentos.getSelectionModel().select("Pasaporte");

You can also do it by index within the combo items, for example to select "Passport" again but in a different way:

TipoDocumentos.getSelectionModel().select(2);

On the other hand, I recommend that you use the methods provided by the SelectionModel better to obtain the selected value:

TipoDocumentos.getSelectionModel(). getSelectedItem();

Greetings and I hope you find it useful.

    
answered by 21.10.2017 / 17:34
source