【发布时间】:2016-08-24 09:10:14
【问题描述】:
@Override
public void start(Stage primaryStage) {
this.primaryStage = primaryStage;
this.primaryStage.setTitle("AddressApp");
initRootLayout();
showTabOverview();
}
/**
* Initializes the root layout.
*/
public void initRootLayout() {
try {
// Load root layout from fxml file.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("rootLayout.fxml"));
rootLayout = (BorderPane) loader.load();
// Show the scene containing the root layout.
Scene scene = new Scene(rootLayout);
primaryStage.setScene(scene);
primaryStage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Shows the Tab overview inside the root layout.
*/
public void showTabOverview() {
try {
// Load person overview.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("tabLayout.fxml"));
TabPane TabOverview = (TabPane) loader.load();
// Set person overview into the center of root layout.
rootLayout.setCenter(TabOverview);
} catch (IOException e) {
e.printStackTrace();
}
}
它确实适用于我的 tabpane 的 FXML。
<TabPane xmlns:fx="http://www.w3.org/1999/XSL/Transform">
<tabs>
<Tab text="Untitled Tab 1">
</Tab>
<Tab text="Untitled Tab 2">
</Tab>
</tabs>
</TabPane>
但我正在尝试使用在 this link 上找到的这种方法添加每个选项卡 FXML
<Tab text="Untitled Tab 1">
<content>
<fx:include fx:id="fooTabPage" source="fooTabPage.fxml"/>
</content>
</Tab>
当我为标签添加包含新源的包含时,它给了我IllegalArgumentException: Unable to coerce javafx.scene.control.Tab@3885406e to class javafx.scene.Node.
如何使这些选项卡实际上成为一个节点?有没有特定的方法来创建它们?
【问题讨论】:
-
您好,Kiper,请在您的问题文本中使用正确的大小写,这样更容易阅读,您可能会获得更多的支持和答案。我已经修好了这个。最好的问候。
-
似乎
fooTabPage.fxml包含一个Tab作为根节点。这应该是Tab的内容。当然你也可以使用Tab作为fooTabPage.fxml的根元素,但是你需要删除周围的<Tab><content></content></Tab>部分,这样fxml变得更难重用了。
标签: javafx