本文介绍了ComboBox FXML默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用FXML在ComboBox中设置默认值?

 < ComboBox fx:id =cbo_Bacteriologie_Aesculine prefHeight =21.0prefWidth =105.0GridPane.columnIndex =1GridPane.rowIndex =0> 
< items>
< FXCollections fx:factory =observableArrayList>
< String fx:value =NVT/>
< String fx:value =Bezig/>
< String fx:value =Positief/>
< String fx:value =Negatief/>
< / FXCollections>
< / items>
< / ComboBox>

我想要 NVT 。我尝试添加 selected =selected等,但似乎找不到正确的语法。



是否可以使用Scene Builder编辑列出的项目?我不能找到它。

解决方案

使用:



pre> < ComboBox>
< items>
< FXCollections fx:factory =observableArrayList>
< String fx:value =NVT/>
< String fx:value =Bezig/>
< String fx:value =Positief/>
< String fx:value =Negatief/>
< / FXCollections>
< / items>
< value>
< String fx:value =NVT/>
< / value>
< / ComboBox>


How can I set a default value in a ComboBox using FXML?

<ComboBox fx:id="cbo_Bacteriologie_Aesculine" prefHeight="21.0" prefWidth="105.0" GridPane.columnIndex="1" GridPane.rowIndex="0">
    <items>
        <FXCollections fx:factory="observableArrayList">
            <String fx:value="NVT" />
            <String fx:value="Bezig" />
            <String fx:value="Positief" />
            <String fx:value="Negatief" />
        </FXCollections>
    </items>
</ComboBox>

I want NVT to be selected by default. I tried adding selected="selected" and such but don't seem to find the right syntax.

Is it possible to edit the listed items using Scene Builder? I can't seem to find it.

解决方案

Use this:

<ComboBox>
    <items>
        <FXCollections fx:factory="observableArrayList">
            <String fx:value="NVT" />
            <String fx:value="Bezig" />
            <String fx:value="Positief" />
            <String fx:value="Negatief" />
        </FXCollections>
    </items>
    <value>
        <String fx:value="NVT" />
    </value>
</ComboBox>

这篇关于ComboBox FXML默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 12:43