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