0
我曾经有一个RootLayout边框窗格,其上有一个fx:includes Anchor窗格,上面有我的控制器。我试图将这两个文件合并成一个.fxml文件,但我遇到了一个问题,试图与我的应用程序的上半部分(按钮,组合框等不可点击)进行交互。我假设我的组织存在问题,或者甚至可能超过高度,但我没有看到它,这是我的第一个javaFX应用程序。如果我在JavaFX Scene Builder中打开.fxml,我只能看到层次结构中的边框窗格。无法与JavaFX控件交互 - 可能的.fxml布局问题
这里是旧体制有两个.fxml文件
老RootLayout.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.BorderPane?>
<BorderPane prefHeight="500.0" prefWidth="500.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<fx:include fx:id="Tabs" source="Tabs.fxml" />
</children>
</BorderPane>
老Tabs.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="asset.view.TabsController">
<children>
<AnchorPane prefHeight="125.0" prefWidth="500.0" AnchorPane.bottomAnchor="375.0">
<children>
<GridPane AnchorPane.leftAnchor="10.0" AnchorPane.topAnchor="35.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="95.0" minWidth="10.0" prefWidth="74.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="125.0" minWidth="125.0" prefWidth="125.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Button mnemonicParsing="false" onAction="#handleInputRecord" text="Submit" GridPane.columnIndex="2">
<GridPane.margin>
<Insets left="5.0" />
</GridPane.margin>
</Button>
<Label text="Employee ID" />
<Label text="Asset ID" GridPane.rowIndex="1" />
<ComboBox fx:id="inputEmployeeIdField" minWidth="125.0" GridPane.columnIndex="1" />
<ComboBox fx:id="inputAssetIdField" minWidth="125.0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
</children>
</GridPane>
</children>
</AnchorPane>
<MenuBar prefWidth="500.0" BorderPane.alignment="CENTER">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" text="Close" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
<AnchorPane prefHeight="375.0" prefWidth="500.0" AnchorPane.topAnchor="125.0">
<children>
<TabPane nodeOrientation="LEFT_TO_RIGHT" prefHeight="375.0" prefWidth="500.0" tabClosingPolicy="UNAVAILABLE">
<tabs>
<Tab text="Overview">
<content>
<SplitPane dividerPositions="0.5761872909698996" focusTraversable="true">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<TableView fx:id="overviewTable" layoutX="-12.5" layoutY="58.0" prefHeight="320.0" prefWidth="175.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columns>
<TableColumn fx:id="overviewAssetIdColumn" minWidth="60.0" text="Asset ID" />
<TableColumn fx:id="overviewEmployeeIdColumn" minWidth="70.0" text="Employee ID" />
<TableColumn fx:id="overviewAssetNameColumn" minWidth="80.0" text="Asset Name" />
<TableColumn fx:id="overviewInventoryStatusColumn" minWidth="50.0" text="Status" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="298.0" prefWidth="400.0">
<children>
<Label layoutX="7.0" layoutY="6.0" text="Overview Details:" AnchorPane.leftAnchor="5.0" AnchorPane.topAnchor="5.0" />
<GridPane layoutX="14.0" layoutY="33.0" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="30.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints />
<ColumnConstraints />
<ColumnConstraints />
<ColumnConstraints />
<ColumnConstraints />
<ColumnConstraints />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Asset ID" />
<Label text="Asset Name" GridPane.rowIndex="1" />
<Label text="Manufacturer" GridPane.rowIndex="2" />
<Label text="Equipment Type" GridPane.rowIndex="3" />
<Label text="Employee ID" GridPane.rowIndex="4" />
<Label text="Employee Name" GridPane.rowIndex="5" />
<Label text="Check Out Date" GridPane.rowIndex="6" />
<Label fx:id="overviewAssetIdLabel" text="Label" GridPane.columnIndex="1" />
<Label fx:id="overviewAssetNameLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label fx:id="overviewManufacturerLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label fx:id="overviewTypeLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Label fx:id="overviewEmployeeIdLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<Label fx:id="overviewEmployeeNameLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="5" />
<Label fx:id="overviewCheckOutDateLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="6" />
<Label fx:id="overviewIdLabel" text="" GridPane.columnIndex="7" />
</children>
</GridPane>
<HBox layoutX="215.0" layoutY="259.0" spacing="5.0" AnchorPane.bottomAnchor="10.0" AnchorPane.rightAnchor="10.0">
<children>
<Button mnemonicParsing="false" onAction="#handleOverviewRefresh" text="Refresh" />
</children>
</HBox>
</children>
</AnchorPane>
</items>
</SplitPane>
</content>
</Tab>
<Tab text="Employees">
<content>
<SplitPane dividerPositions="0.42618729096989966" focusTraversable="true">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<TableView fx:id="employeeTable" layoutX="-12.5" layoutY="58.0" prefHeight="298.0" prefWidth="175.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columns>
<TableColumn fx:id="employeeFirstNameColumn" minWidth="102.0" text="First Name" />
<TableColumn fx:id="employeeLastNameColumn" minWidth="114.0" text="Last Name" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="298.0" prefWidth="393.0">
<children>
<Label layoutX="7.0" layoutY="6.0" text="Employee Details:" AnchorPane.leftAnchor="5.0" AnchorPane.topAnchor="5.0" />
<GridPane layoutX="14.0" layoutY="33.0" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="30.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints />
<ColumnConstraints />
<ColumnConstraints />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Employee ID" />
<Label text="First Name" GridPane.rowIndex="1" />
<Label text="Last Name" GridPane.rowIndex="2" />
<Label text="Status" GridPane.rowIndex="3" />
<Label fx:id="employeeEmployeeIdLabel" text="Label" GridPane.columnIndex="1" />
<Label fx:id="employeeFirstNameLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label fx:id="employeeLastNameLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label fx:id="employeeStatusLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Label fx:id="employeeIdLabel" text="" GridPane.columnIndex="4" />
</children>
</GridPane>
<HBox layoutX="215.0" layoutY="259.0" spacing="5.0" AnchorPane.bottomAnchor="10.0" AnchorPane.rightAnchor="10.0">
<children>
<Button mnemonicParsing="false" onAction="#handleNewEmployee" text="New..." />
<Button mnemonicParsing="false" onAction="#handleEditEmployee" text="Edit..." />
<Button mnemonicParsing="false" onAction="#handleDeleteEmployee" text="Delete" />
</children>
</HBox>
</children>
</AnchorPane>
</items>
</SplitPane>
</content>
</Tab>
</tabs>
</TabPane>
</children>
</AnchorPane>
</children>
</AnchorPane>
新组合Rootlayout.fxml和Tabs.fxml现在命名为RootLayoutTabs.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<BorderPane prefHeight="500.0" prefWidth="500.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="asset.view.TabsController">
<children>
<AnchorPane prefHeight="125.0" prefWidth="500.0" AnchorPane.bottomAnchor="375.0">
<children>
<MenuBar prefWidth="500.0" BorderPane.alignment="CENTER">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" text="Close" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
<GridPane AnchorPane.leftAnchor="10.0" AnchorPane.topAnchor="35.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="95.0" minWidth="10.0" prefWidth="74.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="125.0" minWidth="125.0" prefWidth="125.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Button mnemonicParsing="false" onAction="#handleInputRecord" text="Submit" GridPane.columnIndex="2">
<GridPane.margin>
<Insets left="5.0" />
</GridPane.margin>
</Button>
<Label text="Employee ID" />
<Label text="Asset ID" GridPane.rowIndex="1" />
<ComboBox fx:id="inputEmployeeIdField" minWidth="125.0" GridPane.columnIndex="1" />
<ComboBox fx:id="inputAssetIdField" minWidth="125.0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
</children>
</GridPane>
</children>
</AnchorPane>
<AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<AnchorPane prefHeight="375.0" prefWidth="500.0" AnchorPane.topAnchor="125.0">
<children>
<TabPane nodeOrientation="LEFT_TO_RIGHT" prefHeight="375.0" prefWidth="500.0" tabClosingPolicy="UNAVAILABLE">
<tabs>
<Tab text="Overview">
<content>
<SplitPane dividerPositions="0.5761872909698996" focusTraversable="true">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<TableView fx:id="overviewTable" layoutX="-12.5" layoutY="58.0" prefHeight="320.0" prefWidth="175.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columns>
<TableColumn fx:id="overviewAssetIdColumn" minWidth="60.0" text="Asset ID" />
<TableColumn fx:id="overviewEmployeeIdColumn" minWidth="70.0" text="Employee ID" />
<TableColumn fx:id="overviewAssetNameColumn" minWidth="80.0" text="Asset Name" />
<TableColumn fx:id="overviewInventoryStatusColumn" minWidth="50.0" text="Status" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="298.0" prefWidth="400.0">
<children>
<Label layoutX="7.0" layoutY="6.0" text="Overview Details:" AnchorPane.leftAnchor="5.0" AnchorPane.topAnchor="5.0" />
<GridPane layoutX="14.0" layoutY="33.0" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="30.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints />
<ColumnConstraints />
<ColumnConstraints />
<ColumnConstraints />
<ColumnConstraints />
<ColumnConstraints />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Asset ID" />
<Label text="Asset Name" GridPane.rowIndex="1" />
<Label text="Manufacturer" GridPane.rowIndex="2" />
<Label text="Equipment Type" GridPane.rowIndex="3" />
<Label text="Employee ID" GridPane.rowIndex="4" />
<Label text="Employee Name" GridPane.rowIndex="5" />
<Label text="Check Out Date" GridPane.rowIndex="6" />
<Label fx:id="overviewAssetIdLabel" text="Label" GridPane.columnIndex="1" />
<Label fx:id="overviewAssetNameLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label fx:id="overviewManufacturerLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label fx:id="overviewTypeLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Label fx:id="overviewEmployeeIdLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<Label fx:id="overviewEmployeeNameLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="5" />
<Label fx:id="overviewCheckOutDateLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="6" />
<Label fx:id="overviewIdLabel" text="" GridPane.columnIndex="7" />
</children>
</GridPane>
<HBox layoutX="215.0" layoutY="259.0" spacing="5.0" AnchorPane.bottomAnchor="10.0" AnchorPane.rightAnchor="10.0">
<children>
<Button mnemonicParsing="false" onAction="#handleOverviewRefresh" text="Refresh" />
</children>
</HBox>
</children>
</AnchorPane>
</items>
</SplitPane>
</content>
</Tab>
<Tab text="Employees">
<content>
<SplitPane dividerPositions="0.42618729096989966" focusTraversable="true">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<TableView fx:id="employeeTable" layoutX="-12.5" layoutY="58.0" prefHeight="298.0" prefWidth="175.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columns>
<TableColumn fx:id="employeeFirstNameColumn" minWidth="102.0" text="First Name" />
<TableColumn fx:id="employeeLastNameColumn" minWidth="114.0" text="Last Name" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="298.0" prefWidth="393.0">
<children>
<Label layoutX="7.0" layoutY="6.0" text="Employee Details:" AnchorPane.leftAnchor="5.0" AnchorPane.topAnchor="5.0" />
<GridPane layoutX="14.0" layoutY="33.0" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="30.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints />
<ColumnConstraints />
<ColumnConstraints />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Employee ID" />
<Label text="First Name" GridPane.rowIndex="1" />
<Label text="Last Name" GridPane.rowIndex="2" />
<Label text="Status" GridPane.rowIndex="3" />
<Label fx:id="employeeEmployeeIdLabel" text="Label" GridPane.columnIndex="1" />
<Label fx:id="employeeFirstNameLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label fx:id="employeeLastNameLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label fx:id="employeeStatusLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Label fx:id="employeeIdLabel" text="" GridPane.columnIndex="4" />
</children>
</GridPane>
<HBox layoutX="215.0" layoutY="259.0" spacing="5.0" AnchorPane.bottomAnchor="10.0" AnchorPane.rightAnchor="10.0">
<children>
<Button mnemonicParsing="false" onAction="#handleNewEmployee" text="New..." />
<Button mnemonicParsing="false" onAction="#handleEditEmployee" text="Edit..." />
<Button mnemonicParsing="false" onAction="#handleDeleteEmployee" text="Delete" />
</children>
</HBox>
</children>
</AnchorPane>
</items>
</SplitPane>
</content>
</Tab>
</tabs>
</TabPane>
</children>
</AnchorPane>
</children>
</AnchorPane>
</children>
</BorderPane>
你在FXML中有一些其他奇怪的东西。你设置的BorderPane的孩子有点不明确(我认为),而应该设置顶部/底部/左/右节点。当您直接设置边框窗格的子项时,SceneBuilder甚至不会在层次结构面板中正确显示布局的层次结构。你真的只是从头到尾布局我认为,所以使用VBox而不是BorderPane作为你的根可能更合适。 – jewelsea 2015-03-30 19:09:13