SceneBuilder 节点不可选
SceneBuilder node not selectable
在我的 JavaFX 应用程序中,一些节点显示在预览中但不可选择且不显示在层次结构中。 SceneBuilder 不可定位示例:
在此示例中,"First Name" 列不可定位且不会显示在层次结构中,即使它与 "Last Name" 列具有相同的代码。
"New..." 和 "Edit..." 按钮也一样。
我的SceneBuilder版本是8.3.0。
我正在使用 eclipse,如果必须手动编辑,我正在通过 FXGraph 编辑 fxml。
FXML:
<AnchorPane xmlns:fx="http://javafx.com/fxml" fx:controller="de.is2.address.view.PersonOverviewController" prefHeight="300.0" prefWidth="600.0">
<children>
<SplitPane dividerPositions="0.29797979797979796" layoutX="130.0" layoutY="70.0" prefHeight="300.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<TableView fx:id="personTable" layoutX="-25.0" layoutY="-21.0" prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columns>
<TableColumn fx:id="firstNameColumn" prefWidth="75.0" text="First Name"/>
</columns>
<columns>
<TableColumn fx:id="lastNameColumn" prefWidth="75.0" text="Last Name"/>
</columns>
<columnResizePolicy><TableView fx:constant="CONSTRAINED_RESIZE_POLICY" /></columnResizePolicy>
</TableView>
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<Label layoutX="54.0" layoutY="37.0" text="Person Details" AnchorPane.leftAnchor="5.0" AnchorPane.topAnchor="5.0"/>
<GridPane layoutX="67.0" layoutY="78.0" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="30.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
</columnConstraints>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
</rowConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
</rowConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
</rowConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
</rowConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
</rowConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
</rowConstraints>
<children>
<Label text="First Name"/>
<Label text="Last Name" GridPane.rowIndex="1"/>
<Label text="Street" GridPane.rowIndex="2"/>
<Label text="City" GridPane.rowIndex="3"/>
<Label text="Postal Code" GridPane.rowIndex="4"/>
<Label text="Birthday" GridPane.rowIndex="5"/>
<Label fx:id="firstNameLabel" text="Label" GridPane.columnIndex="1"/>
<Label fx:id="lastNameLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="1"/>
<Label fx:id="streetLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="2"/>
<Label fx:id="cityLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="3"/>
<Label fx:id="postalCodeLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="4"/>
<Label fx:id="birthdayLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="5"/>
</children>
</GridPane>
<ButtonBar layoutX="203.0" layoutY="244.0" prefHeight="39.0" prefWidth="265.0" AnchorPane.bottomAnchor="5.0" AnchorPane.rightAnchor="10.0">
<buttons>
<Button mnemonicParsing="false" text="New..."/>
</buttons>
<buttons>
<Button mnemonicParsing="false" text="Edit..."/>
</buttons>
<buttons>
<Button mnemonicParsing="false" onAction="#handleDeletePerson" text="Delete"/>
</buttons>
</ButtonBar>
</children>
</AnchorPane>
</items>
</SplitPane>
</children>
在您的 FXML 中的多个位置,您重复定义相同标签的内容,如下所示(片段):
<columns>
<TableColumn fx:id="firstNameColumn" prefWidth="75.0" text="First Name"/>
</columns>
<columns> <!-- repetition!! -->
<TableColumn fx:id="lastNameColumn" prefWidth="75.0" text="Last Name"/>
</columns>
这是不正确的 - 您应该打开一次标签,然后指定所有子项,然后关闭一次。您正在为 GridPane 的子项正确执行此操作,例如:
<GridPane layoutX="67.0" layoutY="78.0" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="30.0">
<children>
<Label text="First Name"/>
<Label text="Last Name" GridPane.rowIndex="1"/>
<Label text="Street" GridPane.rowIndex="2"/>
...
</children>
</GridPane>
根据我的经验,JavaFx 本身接受(如预期的那样显示)一些非常有趣的 FXML 构造,但 SceneBuilder 往往更保守,只接受典型的构造。这可能就是为什么预览看起来很好,但层次结构不完整的原因。如果您手动编辑 FXML,请先看一下 SceneBuilder 创建相同结构的方式 - 这就是它所期望的方式。
如果您更正各处的嵌套,则生成的 FXML 为:
<AnchorPane xmlns:fx="http://javafx.com/fxml" fx:controller="de.is2.address.view.PersonOverviewController"
prefHeight="300.0" prefWidth="600.0">
<children>
<SplitPane dividerPositions="0.29797979797979796" layoutX="130.0" layoutY="70.0" prefHeight="300.0"
prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
AnchorPane.topAnchor="0.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<TableView fx:id="personTable" layoutX="-25.0" layoutY="-21.0" prefHeight="200.0"
prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columns>
<TableColumn fx:id="firstNameColumn" prefWidth="75.0" text="First Name" />
<TableColumn fx:id="lastNameColumn" prefWidth="75.0" text="Last Name" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<Label layoutX="54.0" layoutY="37.0" text="Person Details" AnchorPane.leftAnchor="5.0"
AnchorPane.topAnchor="5.0" />
<GridPane layoutX="67.0" layoutY="78.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>
<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>
<children>
<Label text="First Name" />
<Label text="Last Name" GridPane.rowIndex="1" />
<Label text="Street" GridPane.rowIndex="2" />
<Label text="City" GridPane.rowIndex="3" />
<Label text="Postal Code" GridPane.rowIndex="4" />
<Label text="Birthday" GridPane.rowIndex="5" />
<Label fx:id="firstNameLabel" text="Label" GridPane.columnIndex="1" />
<Label fx:id="lastNameLabel" text="Label" GridPane.columnIndex="1"
GridPane.rowIndex="1" />
<Label fx:id="streetLabel" text="Label" GridPane.columnIndex="1"
GridPane.rowIndex="2" />
<Label fx:id="cityLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Label fx:id="postalCodeLabel" text="Label" GridPane.columnIndex="1"
GridPane.rowIndex="4" />
<Label fx:id="birthdayLabel" text="Label" GridPane.columnIndex="1"
GridPane.rowIndex="5" />
</children>
</GridPane>
<ButtonBar layoutX="203.0" layoutY="244.0" prefHeight="39.0" prefWidth="265.0"
AnchorPane.bottomAnchor="5.0" AnchorPane.rightAnchor="10.0">
<buttons>
<Button mnemonicParsing="false" text="New..." />
<Button mnemonicParsing="false" text="Edit..." />
<Button mnemonicParsing="false" onAction="#handleDeletePerson" text="Delete" />
</buttons>
</ButtonBar>
</children>
</AnchorPane>
</items>
</SplitPane>
</children>
</AnchorPane>
这在 SceneBuilder 8.4.1 中给出了我想要的结果:显示 ButtonBar 中的所有 table 列和所有按钮,并在层次结构中选择 table。
在我的 JavaFX 应用程序中,一些节点显示在预览中但不可选择且不显示在层次结构中。 SceneBuilder 不可定位示例:
在此示例中,"First Name" 列不可定位且不会显示在层次结构中,即使它与 "Last Name" 列具有相同的代码。 "New..." 和 "Edit..." 按钮也一样。
我的SceneBuilder版本是8.3.0。 我正在使用 eclipse,如果必须手动编辑,我正在通过 FXGraph 编辑 fxml。
FXML:
<AnchorPane xmlns:fx="http://javafx.com/fxml" fx:controller="de.is2.address.view.PersonOverviewController" prefHeight="300.0" prefWidth="600.0">
<children>
<SplitPane dividerPositions="0.29797979797979796" layoutX="130.0" layoutY="70.0" prefHeight="300.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<TableView fx:id="personTable" layoutX="-25.0" layoutY="-21.0" prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columns>
<TableColumn fx:id="firstNameColumn" prefWidth="75.0" text="First Name"/>
</columns>
<columns>
<TableColumn fx:id="lastNameColumn" prefWidth="75.0" text="Last Name"/>
</columns>
<columnResizePolicy><TableView fx:constant="CONSTRAINED_RESIZE_POLICY" /></columnResizePolicy>
</TableView>
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<Label layoutX="54.0" layoutY="37.0" text="Person Details" AnchorPane.leftAnchor="5.0" AnchorPane.topAnchor="5.0"/>
<GridPane layoutX="67.0" layoutY="78.0" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="30.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
</columnConstraints>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
</rowConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
</rowConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
</rowConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
</rowConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
</rowConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
</rowConstraints>
<children>
<Label text="First Name"/>
<Label text="Last Name" GridPane.rowIndex="1"/>
<Label text="Street" GridPane.rowIndex="2"/>
<Label text="City" GridPane.rowIndex="3"/>
<Label text="Postal Code" GridPane.rowIndex="4"/>
<Label text="Birthday" GridPane.rowIndex="5"/>
<Label fx:id="firstNameLabel" text="Label" GridPane.columnIndex="1"/>
<Label fx:id="lastNameLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="1"/>
<Label fx:id="streetLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="2"/>
<Label fx:id="cityLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="3"/>
<Label fx:id="postalCodeLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="4"/>
<Label fx:id="birthdayLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="5"/>
</children>
</GridPane>
<ButtonBar layoutX="203.0" layoutY="244.0" prefHeight="39.0" prefWidth="265.0" AnchorPane.bottomAnchor="5.0" AnchorPane.rightAnchor="10.0">
<buttons>
<Button mnemonicParsing="false" text="New..."/>
</buttons>
<buttons>
<Button mnemonicParsing="false" text="Edit..."/>
</buttons>
<buttons>
<Button mnemonicParsing="false" onAction="#handleDeletePerson" text="Delete"/>
</buttons>
</ButtonBar>
</children>
</AnchorPane>
</items>
</SplitPane>
</children>
在您的 FXML 中的多个位置,您重复定义相同标签的内容,如下所示(片段):
<columns>
<TableColumn fx:id="firstNameColumn" prefWidth="75.0" text="First Name"/>
</columns>
<columns> <!-- repetition!! -->
<TableColumn fx:id="lastNameColumn" prefWidth="75.0" text="Last Name"/>
</columns>
这是不正确的 - 您应该打开一次标签,然后指定所有子项,然后关闭一次。您正在为 GridPane 的子项正确执行此操作,例如:
<GridPane layoutX="67.0" layoutY="78.0" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="30.0">
<children>
<Label text="First Name"/>
<Label text="Last Name" GridPane.rowIndex="1"/>
<Label text="Street" GridPane.rowIndex="2"/>
...
</children>
</GridPane>
根据我的经验,JavaFx 本身接受(如预期的那样显示)一些非常有趣的 FXML 构造,但 SceneBuilder 往往更保守,只接受典型的构造。这可能就是为什么预览看起来很好,但层次结构不完整的原因。如果您手动编辑 FXML,请先看一下 SceneBuilder 创建相同结构的方式 - 这就是它所期望的方式。
如果您更正各处的嵌套,则生成的 FXML 为:
<AnchorPane xmlns:fx="http://javafx.com/fxml" fx:controller="de.is2.address.view.PersonOverviewController"
prefHeight="300.0" prefWidth="600.0">
<children>
<SplitPane dividerPositions="0.29797979797979796" layoutX="130.0" layoutY="70.0" prefHeight="300.0"
prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
AnchorPane.topAnchor="0.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<TableView fx:id="personTable" layoutX="-25.0" layoutY="-21.0" prefHeight="200.0"
prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columns>
<TableColumn fx:id="firstNameColumn" prefWidth="75.0" text="First Name" />
<TableColumn fx:id="lastNameColumn" prefWidth="75.0" text="Last Name" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<Label layoutX="54.0" layoutY="37.0" text="Person Details" AnchorPane.leftAnchor="5.0"
AnchorPane.topAnchor="5.0" />
<GridPane layoutX="67.0" layoutY="78.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>
<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>
<children>
<Label text="First Name" />
<Label text="Last Name" GridPane.rowIndex="1" />
<Label text="Street" GridPane.rowIndex="2" />
<Label text="City" GridPane.rowIndex="3" />
<Label text="Postal Code" GridPane.rowIndex="4" />
<Label text="Birthday" GridPane.rowIndex="5" />
<Label fx:id="firstNameLabel" text="Label" GridPane.columnIndex="1" />
<Label fx:id="lastNameLabel" text="Label" GridPane.columnIndex="1"
GridPane.rowIndex="1" />
<Label fx:id="streetLabel" text="Label" GridPane.columnIndex="1"
GridPane.rowIndex="2" />
<Label fx:id="cityLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Label fx:id="postalCodeLabel" text="Label" GridPane.columnIndex="1"
GridPane.rowIndex="4" />
<Label fx:id="birthdayLabel" text="Label" GridPane.columnIndex="1"
GridPane.rowIndex="5" />
</children>
</GridPane>
<ButtonBar layoutX="203.0" layoutY="244.0" prefHeight="39.0" prefWidth="265.0"
AnchorPane.bottomAnchor="5.0" AnchorPane.rightAnchor="10.0">
<buttons>
<Button mnemonicParsing="false" text="New..." />
<Button mnemonicParsing="false" text="Edit..." />
<Button mnemonicParsing="false" onAction="#handleDeletePerson" text="Delete" />
</buttons>
</ButtonBar>
</children>
</AnchorPane>
</items>
</SplitPane>
</children>
</AnchorPane>
这在 SceneBuilder 8.4.1 中给出了我想要的结果:显示 ButtonBar 中的所有 table 列和所有按钮,并在层次结构中选择 table。