将JavaFX FlowPane放在BorderPane中并使用FXML

时间:2017-02-04 16:15:11

标签: javafx javafx-8

我是JavaFX的初学者。我正在尝试使用FXML来创建基本布局。我从一个BorderPane开始,在中心,我想制作两个部分,并尝试使用HBox或Flow / Tile窗格。

我知道这是可能的:http://docs.oracle.com/javafx/2/layout/builtin_layouts.htm

但我不知道如何用FXML做到这一点。我真的很难找到任何好的信息。这是我尝试使用HBox的原因:

<BorderPane id="main" prefHeight="500" prefWidth="500" xmlns:fx="http://javafx.com/fxml/1" fx:controller="inventorymanagementsystem.FXMLDocumentController">    
    <top>
        <Label text="Label 1" /> 
    </top>
    <center>
        <HBox alignment="LEFT">
            <children>
                <Label text="Label 2" />
            </children>
        </HBox> 
    </center>
</BorderPane>

但是我得到了这些错误:

Exception in Application start method
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
    at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$152(LauncherImpl.java:182)
    at com.sun.javafx.application.LauncherImpl$$Lambda$51/1343441044.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:745)
Caused by: javafx.fxml.LoadException: 
file:/Users/chelseacamper/NetBeansProjects/InventoryManagementSystem/dist/run174493937/InventoryManagementSystem.jar!/inventorymanagementsystem/FXMLDocument.fxml:18

    at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2605)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2583)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2445)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3218)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3179)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3152)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3128)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3108)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3101)
    at inventorymanagementsystem.InventoryManagementSystem.start(InventoryManagementSystem.java:22)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$159(LauncherImpl.java:863)
    at com.sun.javafx.application.LauncherImpl$$Lambda$54/2067027202.run(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$172(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl$$Lambda$47/355629945.run(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295)
    at com.sun.javafx.application.PlatformImpl$$Lambda$49/147927901.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:294)
    at com.sun.javafx.application.PlatformImpl$$Lambda$48/1915503092.run(Unknown Source)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at com.sun.javafx.fxml.BeanAdapter.coerce(BeanAdapter.java:509)
    at com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:258)
    at com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:54)
    at javafx.fxml.FXMLLoader$Element.applyProperty(FXMLLoader.java:508)
    at javafx.fxml.FXMLLoader$Element.processValue(FXMLLoader.java:359)
    at javafx.fxml.FXMLLoader$Element.processPropertyAttribute(FXMLLoader.java:321)
    at javafx.fxml.FXMLLoader$Element.processInstancePropertyAttributes(FXMLLoader.java:231)
    at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:763)
    at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2827)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2536)
    ... 18 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
    at com.sun.javafx.fxml.BeanAdapter.coerce(BeanAdapter.java:505)
    ... 27 more
Caused by: java.lang.IllegalArgumentException: No enum constant javafx.geometry.Pos.LEFT
    at java.lang.Enum.valueOf(Enum.java:238)
    at javafx.geometry.Pos.valueOf(Pos.java:40)
    ... 38 more
Exception running application inventorymanagementsystem.InventoryManagementSystem
Java Result: 1

任何建议都将不胜感激。

1 个答案:

答案 0 :(得分:1)

当堆栈跟踪明确指出时,LEFT不是HBox alignment property的有效值,而"CENTER_LEFT"期待Pos。根据需要使用"TOP_LEFT""BOTTOM_LEFT"/^[a-zA-Z0-9\\_\\-]{4,16}$/