JacpFX projects have a typical maven project structure.
root | src | | | main | | | java | | | resources | | | bundles (Resource bundles) | | | fxml (FXML files) | | | styles (CSS files) | pom.xml
To start a new JacpFX project you may use a simple Java archetype or one of the JacpFX archetypes.
The JacpFX quickstart archetype provides a simple JacpFX project with one FXWorbench, two FXPerspective(s) (FXML and JavaFX), two FXComponent(s) (FXML and JavaFX) and two CallbackComponent(s).
Since JacpFX 2, Java 8 and JavaFX 8 (u66) is prerequisite.
mvn archetype:generate -DarchetypeGroupId=org.jacpfx -DarchetypeArtifactId=JacpFX-simple-quickstart -DarchetypeVersion=2.1
To build the project go to project root and type:
mvn packge
After the compilation and packaging is finished you may go to the target folder and execute the jar:
cd target && java -jar project-name-app.jar
The goal of the following tutorial is to create a simple JacpFX application similar to the application created by the simple-quickstart archetype
To create a JacpFX application from scratch you may use a simple maven java project. To create one, type:
mvn archetype:create -DgroupId=your.simple.jacpfx.gid -DartifactId=your-simple-jacpfx-aid -DarchetypeArtifactId=maven-archetype-quickstart
Create a resources folder and following subfolders:
bundles, fxml, styles
in your-simple-jacpfx-aid/src/
When finished, go to src/main/java, create a quickstart folder and add workbench, perspective, component, fragment, config, main folders.
Add following JacpFX dependencies:
<dependency>
<groupId>org.jacpfx</groupId>
<artifactId>jacpfx.API</artifactId>
<version>${jacp.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jacpfx</groupId>
<artifactId>jacpfx.JavaFX</artifactId>
<version>${jacp.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jacpfx</groupId>
<artifactId>jacpfx.JavaFXControls</artifactId>
<version>${jacp.version}</version>
<scope>compile</scope>
</dependency>
The launcher project is responsible for the JacpFX-component instance creation. Currently a Spring- and a Simple- launcher is available, so all JacpFX-components are either simple Spring beans or simple POJOs. While the Spring launcher gives you access to the whole Spring universe, the Simple launcher provides a fast startup time.
<dependency>
<groupId>org.jacpfx</groupId>
<artifactId>jacpfx.JavaFXSpring</artifactId>
<version>${jacp.version}</version>
<scope>compile</scope>
</dependency>
or
<dependency>
<groupId>org.jacpfx</groupId>
<artifactId>jacpfx.JavaFXLauncher</artifactId>
<version>${jacp.version}</version>
<scope>compile</scope>
</dependency>
To start the Spring container we need to create either a spring.xml or a spring configuration class like this:
Simply put the BasicConfig class in the config packe created before. A best practice is to put all component and perspective ids as static members to this configuration class and to user this members to reference a specific id.
The ApplicationLauncher contains the main method, the reference to the FXWorkbench implementation, the Spring configuration file and the package names to scann for JacpFX components. Create an ApplicationLauncher class in the main package.
Alternatively you can create a simple JacpFXLauncher without any Spring dependencies and capabilities:
The FXWorkbench is the „root node“ of your JacpFX application. A FXWorkbench creates an application window, defines references to FXPerspective(s) and contains some basic configurations like the initial window size, toolbar definitions and menu definition. Create a JacpFXWorkbench in the workbench package.
Next we create a simple JavaFX based FXPerspective called PerspectiveOne in the perspective package. A perspective defines the basic layout structure of your view, contains references to FXComponent(s) and declares render targets where FXComponent(s) can render their view. PerspectiveOne creates a simple view with a SplitPane which contains two GridPanes, both of them registered as a FXComponent render target.(TARGETCONTAINERLEFT, TARGETCONTAINERMAIN). A FXComponent can now registers itself to be rendered (the view) in one of those areas.
Now we create two FXComponent(s), one with a JavaFX view and the other with a FXML view.
ComponentLeft registers itself to be rendered in TARGETCONTAINERLEFT defined in PerspectiveOne.
The next step is to create a FXML file in /resources/fxml/myview.fxml with the following content:
<GridPane hgap="10" vgap="10" minHeight="-Infinity" minWidth="-Infinity"
xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" GridPane.hgrow="ALWAYS" GridPane.vgrow="ALWAYS">
<children>
<TextArea fx:id="name" text=""/>
<Button onAction="#sayHello" text="%hello" />
</children>
</GridPane>
The corresponding FXController must not implement/return an JavaFX view, instead the root node of your FXML file will be passed as view.
All resource files are located in src/main/resources. The language bundle files are located in src/main/resources/bundles, with the above example resourceBundleLocation = "bundles.languageBundle“ simply add a languageBundleX.properties file, while X is your default locale (en, de, fr, whatever). If you want to use english by default add a languageBundleen.properties file and set localeID = "en" in your @View,@Perspective… annotation.
Now we have created a minimal JacpFX application which you can execute by starting the ApplicationLauncher class in the main package. This small tutorial contains only basic examples to compose your application UI, for advanced topics like messaging feel free to read the documentation