我在使用FXML文件构建JavaFX项目时遇到了问题(手动编写,而不是在SceneBuilder中生成)。以下是FXML文件。这是根据http://docs.oracle.com/javafx/2/get_started/fxml_tutorial.htm中的FXML指令编写的。它产生的实际错误是Caused by: javafx.fxml.LoadException: javafx.scene.layout.GridPane does not have a default property.
我们非常感谢任何帮助。提前谢谢。
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.geometry.Insets?>
<Scene width = "550"
fx:controller = "fxmltableview.FXMLTableViewController"
xmlns:fx = "http://javafx.com/fxml">
<GridPane alignment = "center" hgap = "10" vgap = "10">
<padding> <Insets top = "10" right = "10" bottom = "10" left = "10"/> </padding>
<Label text = "Address Book" GridPane.columnIndex = "0" GridPane.rowIndex = "0" style = "-fx-font: NORMAL 20 Tahoma;"/>
<TableView fx:id = "tableView" GridPane.columnIndex = "0" GridPane.rowIndex = "1">
<columns> <TableColumn text = "First Name"> </TableColumn>
<TableColumn text = "Last Name"> </TableColumn>
<TableColumn text = "email"> </TableColumn>
</columns>
</TableView>
</GridPane>
</Scene>
答案 0 :(得分:1)
您忘记了GridPane的<children>
标记:
<GridPane alignment = "center" hgap = "10" vgap = "10">
<padding> <Insets top = "10" right = "10" bottom = "10" left = "10"/> </padding>
<children>
<Label text = "Address Book" GridPane.columnIndex = "0" GridPane.rowIndex = "0" style = "-fx-font: NORMAL 20 Tahoma;"/>
<TableView fx:id = "tableView" GridPane.columnIndex = "0" GridPane.rowIndex = "1">
<columns> <TableColumn text = "First Name"> </TableColumn>
<TableColumn text = "Last Name"> </TableColumn>
<TableColumn text = "email"> </TableColumn>
</columns>
</TableView>
</children>
</GridPane>
因此,FXML试图将Label和Table放到default
属性中,而这对于GridPane是不可用的。