打开FXML文件

时间:2014-11-05 14:55:41

标签: java user-interface javafx fxml scenebuilder

我试图用JavaFX Scene Builder打开我们项目的fxml文件,但收到错误。

这是一个示例文件:

<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.collections.FXCollections ?>
<?import javafx.constants.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import java.net.URL?>
<ScrollPane xmlns:fx="http://javafx.com/fxml"
            fx:controller="javafx.controller.main.kerNMainController"
            fitToWidth="true"
            fitToHeight="true">

    <GridPane styleClass="root"
              alignment="CENTER_LEFT"
              hgap="10"
              vgap="20">
        <VBox alignment="CENTER">
            <Label text="%kerN.main.welcome.label.text"
                   GridPane.columnIndex="0"
                   GridPane.rowIndex="1"
                   GridPane.halignment="CENTER"
                   fx:id="welcomeLabel"/>

            <Label fx:id="versionLabel" text="%kerN.main.version.label.text" styleClass="outerLabel"/>
        </VBox>

        <VBox alignment="BASELINE_CENTER"
              spacing="40"
              GridPane.columnIndex="0"
              GridPane.rowIndex="2"
              minHeight="550"
              minWidth="550">
            <Button fx:id="assignedTestsAvailableButton"
                    text="%kerN.main.assigned.tests.available.btn.text"
                    onAction="#handleAssignedTestsAvailable"
                    styleClass="assignedTestsButton">
                <minWidth>
                    <Constants fx:constant="LARGE_BUTTON_WIDTH"/>
                </minWidth>
                <minHeight>
                    <Constants fx:constant="DOUBLE_BUTTON_HEIGHT"/>
                </minHeight>
            </Button>
            <Button fx:id="configurationButton"
                    text="%kerN.main.configuration.btn.text"
                    styleClass="configurationButton"
                    onAction="#handleConfiguration">
                <minWidth>
                    <Constants fx:constant="LARGE_BUTTON_WIDTH"/>
                </minWidth>
                <minHeight>
                    <Constants fx:constant="DOUBLE_BUTTON_HEIGHT"/>
                </minHeight>
            </Button>
            <Button fx:id="maintenanceButton"
                    text="%kerN.main.maintenance.btn.text"
                    styleClass="maintenanceButton"
                    onAction="#handleMaintenance">
                <minWidth>
                    <Constants fx:constant="LARGE_BUTTON_WIDTH"/>
                </minWidth>
                <minHeight>
                    <Constants fx:constant="DOUBLE_BUTTON_HEIGHT"/>
                </minHeight>
            </Button>
            <Button fx:id="editTestDataButton"
                    text="%kerN.main.edit.test.data.button.text"
                    onAction="#handleEditTestData"
                    styleClass="editTestDataButton">
                <minWidth>
                    <Constants fx:constant="LARGE_BUTTON_WIDTH"/>
                </minWidth>
                <minHeight>
                    <Constants fx:constant="DOUBLE_BUTTON_HEIGHT"/>
                </minHeight>
            </Button>
            <Button fx:id="testProcessButton"
                    text="%test.process.button.text"
                    onAction="#handleTestProcess"
                    styleClass="testProcessButton">
                <minWidth>
                    <Constants fx:constant="LARGE_BUTTON_WIDTH"/>
                </minWidth>
                <minHeight>
                    <Constants fx:constant="DOUBLE_BUTTON_HEIGHT"/>
                </minHeight>
            </Button>
        </VBox>
    </GridPane>

    <stylesheets>
        <URL value="@../../style/general/Buttons.css"/>
        <URL value="@../../style/main/kerNMain.css"/>
    </stylesheets>
</ScrollPane>

我从Scene Builder获得的错误是

java.io.IOException: javafx.fxml.LoadException: Invalid attribute.
/C:/Users/User/workspace/kerN/src/javafx/frame/main/kerNMain.fxml:37

    at com.oracle.javafx.scenebuilder.kit.fxom.FXOMLoader.load(FXOMLoader.java:92)
    at com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument.<init>(FXOMDocument.java:80)
    at com.oracle.javafx.scenebuilder.kit.fxom.FXOMDocument.<init>(FXOMDocument.java:95)
    at com.oracle.javafx.scenebuilder.kit.editor.EditorController.updateFxomDocument(EditorController.java:2370)
    at com.oracle.javafx.scenebuilder.kit.editor.EditorController.setFxmlTextAndLocation(EditorController.java:655)
    at com.oracle.javafx.scenebuilder.app.DocumentWindowController.loadFromFile(DocumentWindowController.java:386)
    at com.oracle.javafx.scenebuilder.app.SceneBuilderApp.performOpenFiles(SceneBuilderApp.java:579)
    at com.oracle.javafx.scenebuilder.app.SceneBuilderApp.handleOpenFilesAction(SceneBuilderApp.java:447)
    at com.oracle.javafx.scenebuilder.app.SceneBuilderApp.handleLaunch(SceneBuilderApp.java:427)
    at com.oracle.javafx.scenebuilder.app.AppPlatform.requestStartGeneric(AppPlatform.java:139)
    at com.oracle.javafx.scenebuilder.app.AppPlatform.requestStart(AppPlatform.java:106)
    at com.oracle.javafx.scenebuilder.app.SceneBuilderApp.start(SceneBuilderApp.java:371)
    at com.sun.javafx.application.LauncherImpl$8.run(LauncherImpl.java:837)
    at com.sun.javafx.application.PlatformImpl$7.run(PlatformImpl.java:335)
    at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:301)
    at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:298)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl$6.run(PlatformImpl.java:298)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.access$300(WinApplication.java:39)
    at com.sun.glass.ui.win.WinApplication$4$1.run(WinApplication.java:112)
    at java.lang.Thread.run(Thread.java:744)
Caused by: javafx.fxml.LoadException: Invalid attribute.
/C:/Users/User/workspace/kerN/src/javafx/frame/main/kerNMain.fxml:37

    at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2613)
    at javafx.fxml.FXMLLoader.access$100(FXMLLoader.java:104)
    at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:943)
    at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:216)
    at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:738)
    at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2723)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2425)
    at com.oracle.javafx.scenebuilder.kit.fxom.FXOMLoader.load(FXOMLoader.java:89)
    ... 22 more

fxml文件是手动创建的,它们在应用程序中工作但不能在Scene Builder中打开,没有一个......是否有针对此fxml或其他fxml构建器的解决方案?

行:37 <Constants fx:constant="LARGE_BUTTON_WIDTH"/>

1 个答案:

答案 0 :(得分:0)

遵循this指南,应该是:

<Button fx:id="assignedTestsAvailableButton"
        text="%kerN.main.assigned.tests.available.btn.text"
        onAction="#handleAssignedTestsAvailable"
        styleClass="assignedTestsButton">
    <minWidth>
        <Double fx:constant="LARGE_BUTTON_WIDTH"/> <!-- change here -->
    </minWidth>
    <minHeight>
        <Double fx:constant="DOUBLE_BUTTON_HEIGHT"/> <!-- change here -->
    </minHeight>
</Button>