Skip to content

Instantly share code, notes, and snippets.

@nilsding

nilsding/RootLayout.fxml

Last active May 8, 2016
Embed
What would you like to do?
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.ToolBar?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.VBox?>
<BorderPane id="BorderPane" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.72" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.nilsding.j4b.hue02.kurssystem.view.RootLayoutController">
<center>
<TabPane fx:id="tabPane" prefHeight="200.0" prefWidth="200.0" tabClosingPolicy="UNAVAILABLE" BorderPane.alignment="CENTER">
<tabs>
<Tab fx:id="tabKurse" closable="false" text="Kurse" />
<Tab fx:id="tabDozenten" closable="false" text="Dozenten" />
</tabs>
</TabPane>
</center>
<top>
<VBox BorderPane.alignment="CENTER">
<children>
<!-- useSystemMenuBar => use global menu bar on OS X; this fucks up SceneBuilder's menu bar though -->
<MenuBar useSystemMenuBar="true">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" onAction="#handleQuit" text="Quit" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" onAction="#handleAbout" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
<ToolBar prefHeight="40.0" prefWidth="200.0">
<items>
<Button fx:id="buttonRefresh" mnemonicParsing="false" onAction="#handleRefresh" text="Refresh" />
</items>
</ToolBar>
</children>
</VBox>
</top>
</BorderPane>
public class RootLayoutController {
private MainApp mainApp;
@FXML
private Tab tabKurse;
@FXML
private Tab tabDozenten;
private KursOverviewController kursOverviewController;
private DozentOverviewController dozentOverviewController;
/**
* Initializes the controller class.
*/
public void initialize() {
// load tab layouts + controllers
kursOverviewController = loadTab(tabKurse, "KursOverview");
dozentOverviewController = loadTab(tabDozenten, "DozentOverview");
}
/**
* Loads the contents of the tab <tt>tab</tt>.
* @see https://gist.github.com/nilsding/533e528fa9f2dac87b6c992158a8f45b
* @author Georg G. <nilsding@nilsding.org>
* @param tab reference to a JavaFX Tab
* @param name Name of the FXML file without the extension.
*/
private <T> T loadTab(Tab tab, String name) {
try {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(RootLayoutController.class.getResource(name + ".fxml"));
SplitPane content = (SplitPane) loader.load();
T controller = loader.getController();
tab.setContent(content);
return controller;
} catch (IOException ex) {
System.out.println("error while loading tab " + name);
ex.printStackTrace();
return null;
}
}
public void setMainApp(MainApp mainApp) {
this.mainApp = mainApp;
// don't forget to set the mainapp in the underlying controllers as well if you need it there
if (kursOverviewController != null) {
kursOverviewController.setMainApp(mainApp);
}
if (dozentOverviewController != null) {
dozentOverviewController.setMainApp(mainApp);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment