Fixed Scene Loading
This commit is contained in:
Binary file not shown.
@@ -26,6 +26,7 @@ public class App extends Application
|
||||
private ArrayList<Dataset> Datasets = new ArrayList<Dataset>();
|
||||
private Dataset currentDataset = null;
|
||||
private Stage primaryStage = null;
|
||||
private VBox mainContainer;
|
||||
|
||||
public static void main( String[] args )
|
||||
{
|
||||
@@ -38,8 +39,15 @@ public class App extends Application
|
||||
@Override
|
||||
public void start(Stage primaryStage) {
|
||||
this.primaryStage = primaryStage;
|
||||
//load the menu and the first container
|
||||
try {
|
||||
MenuController menuController = new MenuController();
|
||||
FXMLLoader loader = new FXMLLoader();
|
||||
InputStream in = getClass().getClassLoader().getResourceAsStream("menu.fxml");
|
||||
mainContainer = (VBox) loader.load(in);
|
||||
Scene scene = new Scene(mainContainer, 800, 600);
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.sizeToScene();
|
||||
MenuController menuController = (MenuController) loader.getController();
|
||||
menuController.setApp(this);
|
||||
replaceSceneContent("menu.fxml");//replace this to check your fxml file
|
||||
} catch (Exception e) {
|
||||
@@ -81,18 +89,16 @@ public class App extends Application
|
||||
public Initializable replaceSceneContent(String fxml) throws Exception {
|
||||
FXMLLoader loader = new FXMLLoader();
|
||||
InputStream in = getClass().getClassLoader().getResourceAsStream(fxml);
|
||||
InputStream menuIn = getClass().getClassLoader().getResourceAsStream("menu.fxml");
|
||||
VBox page;
|
||||
Parent page;
|
||||
try {
|
||||
page = (VBox) loader.load(menuIn);
|
||||
Parent content = loader.load(getClass().getClassLoader().getResource(fxml));
|
||||
page.getChildren().add(content);
|
||||
page = (Parent) loader.load(in);
|
||||
} finally {
|
||||
in.close();
|
||||
}
|
||||
Scene scene = new Scene(page, 800, 600);
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.sizeToScene();
|
||||
while(mainContainer.getChildren().size() > 1) {
|
||||
mainContainer.getChildren().remove(1);
|
||||
}
|
||||
mainContainer.getChildren().add(page);
|
||||
return (Initializable) loader.getController();
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,8 @@ public class MenuController implements Initializable{
|
||||
*/
|
||||
public void loadAirlineRaw(){
|
||||
try {
|
||||
parent.replaceSceneContent("airline_raw_data.fxml");
|
||||
parent.replaceSceneContent("menu.fxml");
|
||||
System.out.println("Loaded Airline Raw Data.");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.control.Menu?>
|
||||
<?import javafx.scene.control.MenuBar?>
|
||||
<?import javafx.scene.control.MenuItem?>
|
||||
<?import javafx.scene.control.SeparatorMenuItem?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
|
||||
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng202.group9.GUI.MenuController">
|
||||
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng202.group9.GUI.MenuController">
|
||||
<children>
|
||||
<MenuBar>
|
||||
<menus>
|
||||
@@ -31,7 +34,7 @@
|
||||
<Menu mnemonicParsing="false" text="Airline">
|
||||
<items>
|
||||
<MenuItem mnemonicParsing="false" text="Summary" />
|
||||
<MenuItem mnemonicParsing="false" text="Raw Data" />
|
||||
<MenuItem mnemonicParsing="false" onAction="#loadAirlineRaw" text="Raw Data" />
|
||||
</items>
|
||||
</Menu>
|
||||
<Menu mnemonicParsing="false" text="Route">
|
||||
|
||||
Reference in New Issue
Block a user