gpt4 book ai didi

java - 在 ControlsFX CheckComboBox 中设置默认选定的复选框

转载 作者:行者123 更新时间:2023-12-02 09:39:12 24 4
gpt4 key购买 nike

我正在尝试使用 Java 8 设置 ControlsFX CheckComboBox v8.0.3 的默认选定值

我已经尝试过 this question 中接受的答案,但是当我尝试时

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());
}
});

如有任何帮助,我们将不胜感激。

最佳答案

When I try the following I get cannot resolve method check(int);

这是因为您使用的是非常旧版本的 ControlsFX。将您的 ControlsFX 升级到更新版本。

If I try getCheckmodel().selectIndices(0) the first All1 is populated to the CheckComboBox only when a new value is selected from the CheckComboBox.

这似乎是一个错误,已在较新版本的 ControlsFX 中修复。

在 v8.40.14 中,我可以使用 check() 方法设置默认复选框:

checkComboBox.getCheckModel().check(0);

或者,如果您想检查多个项目,则使用 checkIndices() 方法:

checkComboBox.getCheckModel().checkIndices(0, 1);

关于java - 在 ControlsFX CheckComboBox 中设置默认选定的复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57232941/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com