0

我在使用 FXML 文件(手动编写,不在 SceneBuilder 中生成)构建 JavaFX 项目时遇到问题。下面是 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>
4

1 回答 1

1

您忘记<children>了 GridPane 的标签:

<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 放到defaultGridPane 不可用的属性中。

于 2012-07-25T19:30:09.980 回答