我试图设置默认值选择了ControlsFX CheckComboBox v8.0.3
与Java 8
我已经在这个问题中尝试了公认的答案,但是当我尝试
CheckComboBox.getCheckModel().check(0);
我得到一个不能从静态上下文中引用的类。当我尝试以下操作时,我无法解析方法检查(int);
final CheckComboBox<String> checkComboBox = new CheckComboBox<>(strings);
checkComboBox.getCheckModel().check(0);
如果我尝试getCheckmodel().selectIndices(0)
第一个All1
填充到CheckComboBox
只有当从CheckComboBox
. 有没有办法comboxBox
在选择索引后刷新或以任何其他方式实现我想要的?
Text numberTypeText = new Text("Features supported:");
final ObservableList<String> strings = FXCollections.observableArrayList();
strings.add("All1");
strings.add("All2");
strings.add("All3");
strings.add("All4");
strings.add("All5");
strings.add("All6");
strings.add("All7");
strings.add("All8");
final CheckComboBox<String> checkComboBox = new CheckComboBox<>(strings);
checkComboBox.getCheckModel().selectIndices(0);
checkComboBox.getCheckModel().getSelectedItems().addListener(new ListChangeListener<String>() {
public void onChanged(ListChangeListener.Change<? extends String> c) {
System.out.println(checkComboBox.getCheckModel().getSelectedItems());
}
});
任何帮助,将不胜感激。
当我尝试以下操作时,我无法解析方法检查(int);
这是因为您使用的是非常旧版本的 ControlsFX。将您的 ControlsFX 升级到更新版本。
如果我尝试 getCheckmodel().selectIndices(0) ,只有当从 CheckComboBox 中选择新值时,第一个 All1 才会填充到 CheckComboBox。
这似乎是在较新版本的 ControlsFX 中修复的错误。
在 v8.40.14 中,我能够使用check()
方法设置默认复选框:
checkComboBox.getCheckModel().check(0);
或者,checkIndices()
如果要检查多个项目的方法:
checkComboBox.getCheckModel().checkIndices(0, 1);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句