Commit 316c66d6 authored by Benjamin Kech's avatar Benjamin Kech

JavaFX MVC template

parent b33a63c3
# JavaFX Template
# JavaFX MVC Template
Includes an MVC structure to help you get started.
Includes an MVC structure to help you get started with JavaFX.
# Quick start
1. Create a fork of the project from Git
2. Clone project
Eclipse: File → Import → Git → Projects from Git
3. Set JDK 14
Set the project SDK to 14.
4. Create library
Add the JavaFX 14 SDK as a library to the project. Point to the lib folder of the JavaFX SDK.
5. Add VM options
```--module-path /path/to/javafx-sdk-14/lib --add-modules javafx.controls```
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="lib" level="project" />
\ No newline at end of file
package ch.fhnw.template;
public class Controller {
private final Model model;
private final View view;
protected Controller(Model model, View view) {
this.model = model;
this.view = view;
package ch.fhnw.template;
import javafx.application.Application;
import javafx.stage.Stage;
public class Main extends Application {
private Model model;
private View view;
private Controller controller;
public static void main(String[] args) {
* Optional. Program initialization can go here, for example, connection to
* a database, or a network server. The primaryStage is not yet available.
public void init() {
// Nothing to do in this example
* Note the dependencies between model, view and controller. Additionally,
* the view needs access to the primaryStage
public void start(Stage primaryStage) throws Exception{
// Initialize the GUI
model = new Model();
view = new View(primaryStage, model);
controller = new Controller(model, view);
// Display the GUI after all initialization is complete
package ch.fhnw.template;
public class Model {
package ch.fhnw.template;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class View {
private final Model model;
private Stage stage;
protected Label lblHello;
protected View(Stage stage, Model model) {
this.stage = stage;
this.model = model;
stage.setTitle("JavaFX MVC Template");
BorderPane root = new BorderPane();
lblHello = new Label();
lblHello.setText("Hello JavaFX");
Scene scene = new Scene(root);
public void start() {;
* Getter for the stage, so that the controller can access window events
public Stage getStage() {
return stage;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment