2

単純な fxml ファイルを BorderPane または TabPane に含めることができません。いくつかのサンプル コードを含む詳細は、 https ://bitbucket.org/gluon-oss/scenebuilder/issues/68/various-problems-trying-to-inlcude-an-fxml で既に報告されています。

このトピックによると、まだいくつか質問があります。

  1. fx:include できるコンテナの制限はありますか? (たとえば、TabPanes は許可されていませんか??)
  2. 含まれている FXML ファイル内で、行方不明になっている特定のことをしなければなりませんでしたか?
  3. 他のヒントはありますか?

同じ問題が発生した場合は、バグに投票していただければ、修正が得られる可能性が高くなります。

4

1 に答える 1

1

By default, when you include one FXML file into another using Scene Builder menu File -> Include -> FXML..., the included file is added under the root, according the following code:

final FXOMObject rootObject = targetDocument.getFxomRoot();
if (rootObject != null) {
    final Selection selection = getEditorController().getSelection();
    if (selection.isEmpty() || selection.isSelected(rootObject)) {
        targetObject = rootObject;
    } else {
        targetObject = selection.getAncestor();
    }        
    ...
}

In the case of your AnchorWithTabPane.fxml file, if you don't select anything, it will be included under the root:

<AnchorPane ...>
   <children>
     <TabPane  .../>
     <fx:include source="UserControl.fxml" />
   </children>
</AnchorPane>

Now, if you select TabPane, going through the else condition, it will go again under the root, giving that the tabPane's ancestor is the root itself.

If you select Tab, the ancestor is TabPane, but there you can't include a FXML node.

If you select the AnchorPane of a tab, the ancestor is the tab, and you can't include there a FXML node either.

So the solution or workaround in this case is adding some inner container or node to that anchor pane, and then selecting it: since its ancestor will be the AnchorPane, it will add the FXML node there.

include trick

And finally you can delete that temporary container/node.

As a result, you will have:

<TabPane ...>
    <tabs>
      <Tab text="Untitled Tab 1">
        <content>
          <AnchorPane ...>
                 <children>
                    <fx:include source="UserControl.fxml" />
                 </children>
          </AnchorPane>
        </content>
      </Tab>
      <Tab text="Untitled Tab 2">
        <content>
          <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
        </content>
      </Tab>
    </tabs>

Regarding your question about what containers can hold an fx:include, all the panes under javafx.scene.layout.* can hold them.

As hint, if you use NetBeans, edit an fxml file, and within the container tags click Ctrl+space, it will show you if the fx:include node is allowed:

fx:include

于 2016-03-18T17:37:02.783 に答える