JavaFX& FXML:如何在FXML中的ChoiceBox中设置默认选定项? [英] JavaFX & FXML: how do I set the default selected item in a ChoiceBox in FXML?

查看:1252
本文介绍了JavaFX& FXML:如何在FXML中的ChoiceBox中设置默认选定项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下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中它只显示一个默认为nothing的ChoiceBox。我希望列表中的第一个元素是默认值,并且选择null或者不禁止任何内容。

But in the GUI it just shows a ChoiceBox with a default of nothing. I would like the first element in the list to be the default, and for a choice of "null" or nothing to be prohibited.

我该如何做到这一点? / p>

How do I accomplish this?

推荐答案

我在ChoiceBox标签中添加了value属性,并且工作正常。

I added the value attribute to the ChoiceBox tag, and that worked.

<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&amp; FXML:如何在FXML中的ChoiceBox中设置默认选定项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆