我的应用程序有选项卡式窗格,所以为了保持fxml文件的可管理性,我有一个包含选项卡的主fxml文件,并为每个其他选项卡单独设置一个fxml。这很好,但出于某种原因,应用程序已经停止加载第二个标签。我试着在主应用程序中单独加载它,效果很好。我尝试创建一个新的fxml文件作为测试,并加载它,这也是有效的。但是,它不会将其加载到第二个选项卡中。此外,控制台没有输出。
@Override
public void start(Stage primaryStage) {
Parent mainView;
try {
mainView = FXMLLoader.load(getClass().getResource("view/MainView.fxml"));
Scene scene = new Scene(mainView);
primaryStage.setTitle("Horse Show Manager");
primaryStage.setScene(scene);
primaryStage.show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.GridPane?>
<TabPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0"
prefWidth="800.0" tabClosingPolicy="UNAVAILABLE" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8">
<tabs>
<Tab text="Classes">
<fx:include source="GroupPane.fxml" fx:id="groupPaneContent" />
</Tab>
<Tab text="Riders">
<fx:include source="RiderPane.fxml" fx:id="riderPaneContent" />
</Tab>
</tabs>
</TabPane>
<?import javafx.collections.*?>
<?import javafx.geometry.*?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.collections.FXCollections?>
<SplitPane dividerPositions="0.4" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="application.view.GroupPaneController">
<items>
<TableView fx:id="table" editable="true" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
<columns>
<TableColumn fx:id="groupNumberColumn" editable="false" prefWidth="40.0" text="Class Number" />
<TableColumn fx:id="groupNameColumn" editable="false" prefWidth="40.0" text="Class Name" />
</columns>
</TableView>
<GridPane alignment="CENTER">
<columnConstraints>
<ColumnConstraints hgrow="NEVER" />
<ColumnConstraints hgrow="ALWAYS" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" vgrow="NEVER" />
<RowConstraints vgrow="NEVER" />
<RowConstraints vgrow="NEVER" />
<RowConstraints vgrow="NEVER" />
<RowConstraints vgrow="NEVER" />
<RowConstraints vgrow="NEVER" />
<RowConstraints vgrow="ALWAYS" />
</rowConstraints>
<children>
<Label text="Number">
<GridPane.margin>
<Insets bottom="10.0" left="5.0" right="5.0" top="10.0" />
</GridPane.margin>
</Label>
<Label text="Extra Money" GridPane.rowIndex="4">
<GridPane.margin>
<Insets bottom="10.0" left="5.0" right="5.0" top="10.0" />
</GridPane.margin>
</Label>
<Label text="Fee" GridPane.rowIndex="3">
<GridPane.margin>
<Insets bottom="10.0" left="5.0" right="5.0" top="10.0" />
</GridPane.margin>
</Label>
<Label text="Gives Points" GridPane.rowIndex="5">
<GridPane.margin>
<Insets bottom="10.0" left="5.0" right="5.0" top="10.0" />
</GridPane.margin>
</Label>
<Label text="Name" GridPane.rowIndex="1">
<GridPane.margin>
<Insets bottom="10.0" left="5.0" right="5.0" top="10.0" />
</GridPane.margin>
</Label>
<Label text="Placing" GridPane.rowIndex="2">
<GridPane.margin>
<Insets bottom="10.0" left="5.0" right="5.0" top="10.0" />
</GridPane.margin>
</Label>
<HBox alignment="TOP_RIGHT" prefHeight="100.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="6">
<children>
<Button fx:id="addButton" mnemonicParsing="false" onAction="#groupAddOrEdit" text="Add">
<HBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</HBox.margin>
</Button>
<Button fx:id="editButton" mnemonicParsing="false" onAction="#editing" text="Edit">
<HBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</HBox.margin>
</Button>
<Button fx:id="deleteButton" mnemonicParsing="false" onAction= "#deleteGroup" text="Delete">
<HBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</HBox.margin>
</Button>
</children>
</HBox>
<TextField fx:id="numberField" GridPane.columnIndex="1">
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</GridPane.margin>
</TextField>
<TextField fx:id="nameField" GridPane.columnIndex="1" GridPane.rowIndex="1">
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</GridPane.margin>
</TextField>
<TextField fx:id="feeField" GridPane.columnIndex="1" GridPane.rowIndex="3">
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</GridPane.margin>
</TextField>
<TextField fx:id="extraMoneyField" GridPane.columnIndex="1" GridPane.rowIndex="4">
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</GridPane.margin>
</TextField>
<ChoiceBox fx:id="givesPointsChoiceBox" maxWidth="1.7976931348623157E308" GridPane.columnIndex="1"
GridPane.hgrow="ALWAYS" GridPane.rowIndex="5">
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</GridPane.margin>
<items>
<FXCollections fx:factory="observableArrayList">
<String fx:value="No" />
<String fx:value="Yes" />
</FXCollections>
</items>
<value>
<String fx:value="Yes" />
</value>
</ChoiceBox>
<ChoiceBox fx:id="gradingChoiceBox" maxWidth="1.7976931348623157E308" GridPane.columnIndex="1"
GridPane.rowIndex="2">
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</GridPane.margin>
<items>
<FXCollections fx:factory="observableArrayList">
<String fx:value="Place" />
<String fx:value="Time" />
<String fx:value="Points" />
</FXCollections>
</items>
<value>
<String fx:value="Place" />
</value>
</ChoiceBox>
</children>
</GridPane>
</items>
</SplitPane>
第二个:
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<SplitPane dividerPositions="0.5" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<items>
<VBox>
<children>
<TableView VBox.vgrow="ALWAYS">
<columns>
<TableColumn prefWidth="75.0" text="C1" />
<TableColumn prefWidth="75.0" text="C2" />
</columns>
<VBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</VBox.margin>
</TableView>
<TableView VBox.vgrow="ALWAYS">
<columns>
<TableColumn prefWidth="75.0" text="C1" />
<TableColumn prefWidth="75.0" text="C2" />
</columns>
<VBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</VBox.margin>
</TableView>
</children>
</VBox>
<GridPane>
<columnConstraints>
<ColumnConstraints />
<ColumnConstraints hgrow="NEVER" minWidth="0.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="0.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="0.0" vgrow="NEVER" />
<RowConstraints minHeight="0.0" vgrow="NEVER" />
<RowConstraints minHeight="0.0" vgrow="NEVER" />
<RowConstraints minHeight="0.0" vgrow="NEVER" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="NEVER" />
<RowConstraints minHeight="0.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="0.0" vgrow="NEVER" />
<RowConstraints minHeight="0.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="0.0" vgrow="NEVER" />
</rowConstraints>
<children>
<Label text="Number" GridPane.columnIndex="1">
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</GridPane.margin>
</Label>
<Label text="Name" GridPane.columnIndex="1" GridPane.rowIndex="1">
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</GridPane.margin>
</Label>
<Label text="Fee" GridPane.columnIndex="1" GridPane.rowIndex="2">
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</GridPane.margin>
</Label>
<Label text="Membership" GridPane.columnIndex="1" GridPane.rowIndex="3">
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</GridPane.margin>
</Label>
<TextField GridPane.columnIndex="2">
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</GridPane.margin>
</TextField>
<TextField GridPane.columnIndex="2" GridPane.rowIndex="1">
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</GridPane.margin>
</TextField>
<VBox GridPane.columnIndex="2" GridPane.rowIndex="3">
<children>
<RadioButton mnemonicParsing="false" text="Current Member">
<VBox.margin>
<Insets left="5.0" right="5.0" top="5.0" />
</VBox.margin>
<toggleGroup>
<ToggleGroup fx:id="membershipGroup" />
</toggleGroup>
</RadioButton>
<RadioButton mnemonicParsing="false" text="Single Membership" toggleGroup="$membershipGroup">
<VBox.margin>
<Insets left="5.0" right="5.0" top="5.0" />
</VBox.margin>
</RadioButton>
<RadioButton mnemonicParsing="false" text="Family Membership" toggleGroup="$membershipGroup">
<VBox.margin>
<Insets left="5.0" right="5.0" top="5.0" />
</VBox.margin>
</RadioButton>
<RadioButton mnemonicParsing="false" text="Non-member" toggleGroup="$membershipGroup">
<VBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</VBox.margin>
</RadioButton>
</children>
</VBox>
<TableView prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.columnSpan="2147483647" GridPane.rowIndex="5">
<columns>
<TableColumn editable="false" maxWidth="1.7976931348623157E308" minWidth="-Infinity" prefWidth="187.0" text="Horses" />
</columns>
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</GridPane.margin>
</TableView>
<TableView prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.columnSpan="2147483647" GridPane.rowIndex="7">
<columns>
<TableColumn prefWidth="75.0" text="Class Number" />
<TableColumn prefWidth="75.0" text="Class Name" />
</columns>
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</GridPane.margin>
</TableView>
<HBox GridPane.columnIndex="1" GridPane.columnSpan="2147483647" GridPane.rowIndex="6">
<children>
<TextField HBox.hgrow="ALWAYS">
<HBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</HBox.margin>
</TextField>
<Button mnemonicParsing="false" text="Button">
<HBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</HBox.margin>
</Button>
</children>
</HBox>
<HBox alignment="CENTER" GridPane.columnIndex="1" GridPane.columnSpan="2147483647" GridPane.rowIndex="8" GridPane.valignment="CENTER">
<children>
<Button alignment="CENTER" mnemonicParsing="false" text="Button" HBox.hgrow="ALWAYS">
<HBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</HBox.margin>
</Button>
<Button alignment="CENTER" mnemonicParsing="false" text="Button" HBox.hgrow="ALWAYS">
<HBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</HBox.margin>
</Button>
</children>
</HBox>
<HBox prefHeight="100.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.columnSpan="2147483647" GridPane.rowIndex="4">
<children>
<TextField HBox.hgrow="ALWAYS">
<HBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</HBox.margin>
</TextField>
<Button mnemonicParsing="false" text="Add Horse">
<HBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</HBox.margin>
</Button>
</children>
</HBox>
<TextField GridPane.columnIndex="2" GridPane.rowIndex="2">
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</GridPane.margin>
</TextField>
</children>
</GridPane>
</items>
</SplitPane>
很抱歉代码太长,并提前感谢您的帮助!
我认为回答我自己的问题可能是糟糕的形式...但解决方案是用fx:define和fx:include标记定义两个标签。然后可以加载fxml内容。下面的例子。
<TabPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0"
prefWidth="800.0" tabClosingPolicy="UNAVAILABLE" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<fx:define>
<fx:include fx:id="groupPaneContent" source="GroupPane.fxml" />
<fx:include fx:id="riderPaneContent" source="RiderPane.fxml" />
</fx:define>
<tabs>
<Tab closable="false" text="Classes" content="$groupPaneContent" />
<Tab closable="false" text="Riders" content="$riderPaneContent" />
</tabs>
</TabPane>
编辑:FXML最初呈现不正确。我必须手动调整应用程序的大小,这样它就会出现。如果你知道如何解决这个问题,请发表评论
项目/ SRC/ 主/ Java/ 资源/ baselayout.fxml 不是应该有用吗?我本来工作得很好,但突然就不是了。我不知道还能做什么。
我与运行mac os的项目成员在加载FXML时遇到问题。我对java代码中的整个JavaFX加载过程相当陌生,但目前我的代码就是这样编写的。这个类叫做ControlPanel.java,fxml是ControlPanel.fxml,它包含onAction方法,我使用ControlPanel.java作为这些方法的控制器。它在windows操作系统上运行完全正常,但当我们尝试在eclipse中运行它
当查看JavaFX SceneBuilder时,它能够加载任何类型的FXML。则忽略根节点或控制器。scenebuilder能够加载任何类型的fxml并显示其组件。 有没有人想要一种方法来加载一个fxml,而不考虑其字段的ID、控制器或根节点的类型? 问题是,当我尝试加载任何fxml时,它只能加载,如果我设置了正确的根类型。我想(通过FileChooser)将我能找到的任何FXML加载到(比方说)
我需要创建许多不同的FXML文件,每个文件都有一个一致的布局。每一个都有一个锚烷,可以容纳不同的内容物。 有没有办法加载一个“基本”FXML文件,然后加载第二个FXML文件,并将数据路由到第一个FXML文件? 例如,FXML#1有一个边框。FXML#2有一个按钮,文本字段,标签等。如何加载#1,然后加载#2作为#1的孩子?
我在打开我的时遇到问题。当我运行项目时,一切都运行得很好,但是我不能在下进行修改。每次我想要添加到中时,我都需要删除包含,做我想做的,并手动将代码粘贴到中,而不是粘贴到中(不能在Tab下包含?)。
大家好,我是fxml的新手,所以请忽略我的愚蠢的问题,这里有几个东西,我尝试了两天,但没有成功 > 从表中删除空白,即表大小应达到可用行数(行数不同) 当用户单击表行(任何显示值)时,新的fxml文件将在定位窗格(显示tableview)中打开,分配给tableview,但我想在主视图中显示它(这里显示的是整个表和两个文本字段以及主堆栈后面的搜索按钮)主视图(其他只有标题和侧栏的fxml文件) 如