简体   繁体   中英

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 应返回 FALSE

Checking for ComboBox in this state should return TRUE: 此状态下的 ComboBox 应返回 TRUE

You can use

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

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

于是我找到了一个简单的方法:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM