簡體   English   中英

填充ComboBox后,FXML場景構建器無效屬性

[英]FXML scene builder invalid attribute after filling ComboBox

我有這個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"它會在場景構建器上加載並顯示警告,但仍然無法運行我的程序。

我不太明白,因為它與我在許多示例example1example2example3中看到的方式相同。

為什么我收到此錯誤? 不應該工作嗎?

我知道如何通過代碼填充元素,但我正在尋找FXML解決方案。

您需要為FXCollections類導入:

<?import javafx.collections.FXCollections ?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM