0

私のアプリにはタブ付きのペインがあるため、fxml ファイルを管理しやすくするために、タブを含むメインの fxml ファイルと、他のタブごとに個別の fxml があります。これは正常に機能していましたが、何らかの理由で、アプリが 2 番目のタブの読み込みを停止しました。メインアプリでソロをロードしてみましたが、問題なく動作します。テストとして新しい fxml ファイルを作成してロードしようとしましたが、これも機能します。ただし、2 番目のタブには読み込まれません。また、コンソールへの出力はありません。

編集:さらに試行錯誤した後、分割ペインに絞り込みました。ボタン付きの非常に単純な fxml を試してみましたが、これは問題ありませんでしたが、分割ペインと 2 つのボタンを追加すると、ビューがレンダリングされません。

これが私のメインクラスです: public class Main extends Application {

@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);
}
}

これが私のmainview.fxmlです

<?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>

そして2番目:

<?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>

長いコードで申し訳ありませんが、助けてくれてありがとう!

4

1 に答える 1

1

私自身の質問に答えるのは悪い形かもしれないと思います...しかし、解決策は fx:define タグと fx:include タグで 2 つのタブを定義することです。その後、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 は最初は正しくレンダリングされません。アプリが表示されるように、アプリのサイズを手動で変更する必要があります。これを修正する方法を知っている場合は、コメントを残してください

于 2014-06-25T04:15:25.017 に答える