-
-
Save hastebrot/9283038 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<?import javafx.scene.control.*?> | |
<?import javafx.scene.layout.*?> | |
<?scenebuilder-stylesheet vista.css?> | |
<VBox prefHeight="200.0" prefWidth="300.0" xmlns:fx="http://javafx.com/fxml" fx:controller="MainController"> | |
<children> | |
<Label fx:id="headerLabel" maxWidth="1.7976931348623157E308" text="Header" VBox.vgrow="NEVER" /> | |
<StackPane fx:id="vistaHolder" VBox.vgrow="ALWAYS" /> | |
</children> | |
</VBox> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javafx.application.Application; | |
import javafx.fxml.FXMLLoader; | |
import javafx.scene.Scene; | |
import javafx.scene.layout.Pane; | |
import javafx.stage.Stage; | |
import java.io.IOException; | |
/** | |
* Main application class. | |
*/ | |
public class Main extends Application { | |
@Override | |
public void start(Stage stage) throws Exception{ | |
stage.setTitle("Vista Viewer"); | |
stage.setScene( | |
createScene( | |
loadMainPane() | |
) | |
); | |
stage.show(); | |
} | |
/** | |
* Loads the main fxml layout. | |
* Sets up the vista switching VistaNavigator. | |
* Loads the first vista into the fxml layout. | |
* | |
* @return the loaded pane. | |
* @throws IOException if the pane could not be loaded. | |
*/ | |
private Pane loadMainPane() throws IOException { | |
FXMLLoader loader = new FXMLLoader(); | |
Pane mainPane = (Pane) loader.load( | |
getClass().getResourceAsStream( | |
VistaNavigator.MAIN | |
) | |
); | |
MainController mainController = loader.getController(); | |
VistaNavigator.setMainController(mainController); | |
VistaNavigator.loadVista(VistaNavigator.VISTA_1); | |
return mainPane; | |
} | |
/** | |
* Creates the main application scene. | |
* | |
* @param mainPane the main application layout. | |
* | |
* @return the created scene. | |
*/ | |
private Scene createScene(Pane mainPane) { | |
Scene scene = new Scene( | |
mainPane | |
); | |
scene.getStylesheets().setAll( | |
getClass().getResource("vista.css").toExternalForm() | |
); | |
return scene; | |
} | |
public static void main(String[] args) { | |
launch(args); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javafx.fxml.FXML; | |
import javafx.scene.Node; | |
import javafx.scene.layout.StackPane; | |
/** | |
* Main controller class for the entire layout. | |
*/ | |
public class MainController { | |
/** Holder of a switchable vista. */ | |
@FXML | |
private StackPane vistaHolder; | |
/** | |
* Replaces the vista displayed in the vista holder with a new vista. | |
* | |
* @param node the vista node to be swapped in. | |
*/ | |
public void setVista(Node node) { | |
vistaHolder.getChildren().setAll(node); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* vista.css | |
* Place in the same source directory as Main.java | |
* Ensure that your build system copies this file to your build output directory. | |
*/ | |
#headerLabel { | |
-fx-background-color: steelblue; | |
-fx-text-fill: white; | |
-fx-padding: 5px; | |
} | |
#vistaHolder { | |
-fx-background-color: lightgrey; | |
} | |
#vista1 { | |
-fx-background-color: aliceblue; | |
} | |
#vista2 { | |
-fx-background-color: coral; | |
} | |
.button { | |
-fx-base: lightblue; | |
-fx-font-size: 20px; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<?import javafx.scene.control.*?> | |
<?import javafx.scene.layout.*?> | |
<?scenebuilder-stylesheet vista.css?> | |
<StackPane fx:id="vista1" xmlns:fx="http://javafx.com/fxml" fx:controller="Vista1Controller"> | |
<children> | |
<Button mnemonicParsing="false" onAction="#nextPane" text="Next Pane" /> | |
</children> | |
</StackPane> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javafx.event.ActionEvent; | |
import javafx.fxml.FXML; | |
/** | |
* Controller class for the first vista. | |
*/ | |
public class Vista1Controller { | |
/** | |
* Event handler fired when the user requests a new vista. | |
* | |
* @param event the event that triggered the handler. | |
*/ | |
@FXML | |
void nextPane(ActionEvent event) { | |
VistaNavigator.loadVista(VistaNavigator.VISTA_2); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<?scenebuilder-stylesheet vista.css?> | |
<?import javafx.scene.control.Button?> | |
<?import javafx.scene.layout.StackPane?> | |
<StackPane fx:id="vista2" xmlns:fx="http://javafx.com/fxml" fx:controller="Vista2Controller"> | |
<children> | |
<Button mnemonicParsing="false" onAction="#previousPane" text="Previous Pane" /> | |
</children> | |
</StackPane> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javafx.event.ActionEvent; | |
import javafx.fxml.FXML; | |
/** | |
* Controller class for the second vista. | |
*/ | |
public class Vista2Controller { | |
/** | |
* Event handler fired when the user requests a previous vista. | |
* | |
* @param event the event that triggered the handler. | |
*/ | |
@FXML | |
void previousPane(ActionEvent event) { | |
VistaNavigator.loadVista(VistaNavigator.VISTA_1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment