java 如何检查是否在 JavaFX ComboBox 中选择了任何项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36963551/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 02:03:28  来源:igfitidea点击:

How to check if any item is selected in JavaFX ComboBox

javajavafxcombobox

提问by PeterB

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

检查 JavaFX ComboBox 中是否选择了任何项目或是否没有选择项目的简单方法是什么?

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

在此状态下检查 ComboBox 应返回 FALSE: 此状态下的 ComboBox 应返回 FALSE

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

在此状态下检查 ComboBox 应返回 TRUE: 此状态下的 ComboBox 应返回 TRUE

回答by fabian

You can use

您可以使用

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

Which also works, if you have a nullitem among the ComboBoxitems.

如果您在null项目中有一个项目,这也有效ComboBox

回答by PeterB

So I found a simple way:

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

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

回答by Andres Bonfil

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