gpt4 book ai didi

javafx-2 - JavaFX 和 FXML : how do I set the default selected item in a ChoiceBox in FXML?

转载 作者:行者123 更新时间:2023-12-04 11:10:55 24 4
gpt4 key购买 nike

我有以下 FXML:

<ChoiceBox>
<items>
<FXCollections fx:factory="observableArrayList">
<String fx:value="2 minutes" />
<String fx:value="5 minutes" />
<String fx:value="15 minutes" />
</FXCollections>
</items>
</ChoiceBox>

但在 GUI 中,它只显示一个默认为空的 ChoiceBox。我希望列表中的第一个元素是默认元素,并选择“null”或禁止任何内容。

我该如何实现?

最佳答案

我将 value 属性添加到 ChoiceBox 标记,并且奏效了。

<ChoiceBox value="2 minutes">
<items>
<FXCollections fx:factory="observableArrayList">
<String fx:value="2 minutes" />
<String fx:value="5 minutes" />
<String fx:value="15 minutes" />
</FXCollections>
</items>
</ChoiceBox>

关于javafx-2 - JavaFX 和 FXML : how do I set the default selected item in a ChoiceBox in FXML?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18244943/

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