Wesos de Queso
Wesos de Queso

Reputation: 1572

JavaFX Combox when something is selected property

I have this large BooleanBinding.

BooleanBinding uncompleteBinding = txtBarcode.textProperty().isEmpty()
                            .or(txtNombre.textProperty().isEmpty()
                            .or(txtPrecioContado.textProperty().isEmpty())
                            .or(txtPrecioCredito.textProperty().isEmpty())
                            .or(txtModelo.textProperty().isEmpty()
                            .or(txtSerie.textProperty().isEmpty()

                            .or(cboCategoria.selectionModelProperty().isNull()
))));

The purpouse of the BooleanBinding is to enable a save button. It was working fine until i added Combobox into the mix. It doesn't seem to work that way. I tried isNotNull() and itemsProperty() as well.

By defaul't Combobox displays a "-" and nothing is selected. Is requiered that the user selects something, and there is no default selected value allowed.

Upvotes: 2

Views: 776

Answers (2)

fabian
fabian

Reputation: 82461

Use the value property to check the value chosen in the ComboBox and use "-" as prompt text.

Example:

ComboBox<String> cb = new ComboBox<>();
cb.getItems().setAll("A", "B", "C");
cb.setPromptText("-");

Button btn = new Button("Submit");
btn.disableProperty().bind(cb.valueProperty().isNull());

Upvotes: 5

Dmytro Maslenko
Dmytro Maslenko

Reputation: 2287

Try this idea:

comboBox.getSelectionModel().selectedIndexProperty().isEqualTo(0);

where your "-" is located under 0 index.

Upvotes: 0

Related Questions