我有这个 FXML 文件,我试图在其中填充 ComboBox:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="650.0" minWidth="750.0" prefHeight="700.0" prefWidth="822.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="table.Table">
<children>
<MenuButton fx:id="dateFilter" layoutX="6.0" layoutY="55.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="114.0" text="Date" />
<ComboBox fx:id="descriptionFilter" editable="true" layoutX="226.0" layoutY="55.0" prefHeight="25.0" prefWidth="204.0" promptText="Series Description">
<items>
<FXCollections fx:factory="observableArrayList">
<String fx:value="1" />
<String fx:value="20" />
<String fx:value="300" />
</FXCollections>
</items>
</ComboBox>
</children>
</AnchorPane>
但是由于我填充了它,它不会在 SceneBuilder 上打开并且显示此错误:
错误
java.io.IOException: javafx.fxml.LoadException: Invalid attribute. /C:/Users/BTAP/workspace/Tst/src/table/table.fxml:12
它不会加载我的应用程序:
Caused by: javafx.fxml.LoadException: FXCollections is not a valid type.
注意事项
如果我删除 fx:factory="observableArrayList"
,它会在场景构建器上加载并显示警告,但仍然不会运行我的程序。
我不太明白,因为它和我在很多例子中看到的一样example1 , example2 , example3 .
为什么会出现此错误?它不应该起作用吗?
我知道如何通过代码填充元素,但我正在寻找 FXML 解决方案。
最佳答案
您需要导入 FXCollections
类:
<?import javafx.collections.FXCollections ?>
关于java - 填充 ComboBox 后 FXML 场景生成器无效属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24396897/