PeterB
PeterB

Reputation: 2414

How to check if any item is selected in JavaFX ComboBox

What is the simple way to check whether any item is selected in JavaFX ComboBox or if it is left without selected item?

Checking for ComboBox in this state should return FALSE: ComboBox in this state should return FALSE

Checking for ComboBox in this state should return TRUE: ComboBox in this state should return TRUE

Upvotes: 7

Views: 28397

Answers (3)

Andres Bonfil
Andres Bonfil

Reputation: 1

!(cmbDia.getValue()==null) && !(cmbMes.getValue()==null) && !(cmbAno.getValue()==null)//fue todo gracias :)

Upvotes: 0

PeterB
PeterB

Reputation: 2414

So I found a simple way:

boolean isMyComboBoxEmpty = (myComboBox.getValue() == null);

Upvotes: 9

fabian
fabian

Reputation: 82461

You can use

boolean isMyComboBoxEmpty = myComboBox.getSelectionModel().isEmpty();

Which also works, if you have a null item among the ComboBox items.

Upvotes: 22

Related Questions