JavaFX is a new platform for creating and deploying rich Internet applications inside a lightweight Java virtual machine. JavaFX Studio works as an Eclipse plugin for developing and deploying JavaFX applications. JavaFX Studio comes with numerous features and wizards to make JavaFX application development better.
Table 2.1. Key Features of Exadel JavaFX Studio
| Feature | Description |
|---|---|
| Multi project support | If a project depends on some other project the plug-in can resolve the dependencies during compiling, launching and code-assist. |
| Code Assist | Completes your code statements faster and with more accuracy |
| JavaFX Examples | Exadel JavaFX Studio enables you to open a example project (standard Sun JavaFX examples) and run it from the studio |
| Enable JavaFX Support | Exadel JavaFX Studio enables you add JavaFX capabilities to any Java project. |
Install JavaFX SDK
Download JavaFX SDK for Windows or Linux. Follow the installation instructions.
Install Eclipse
The Plugin requires Eclipse 3.5. We recommend downloading "Eclipse IDE for Java EE Developers" for Windows or Linux. Then follow the installation instructions.
Start the Eclipse IDE
Once Eclipse is started you can install the plugin. You need to navigate to Help > Install New Software on the main menu.
Hit Add in the Available Software dialog box.
In the Add Site dialog box, in the Name input field enter Exadel JavaFX and in the Location text field type(or paste)one of the following links:
Latest stable release: http://download.exadel.org/javafx_plugin/updates/stable/
Latest nightly build: http://download.exadel.org/javafx_plugin/updates/nightly/
InClick Ok to proceed.
Select the Exadel JavaFX checkbox and click Next.
In the Install Details dialog box click Next.
Review and accept the terms of the license agreement and click Finish.
Eclipse proceeds with the installation of the Exadel JavaFX plugin.
When prompted to restart the Eclipse Platform, press Yes.
In this chapter you will learn how to create projects with Exadel JavaFX Studio. The fist project is quite elementary, you will create a JavaFX script file, set up the configuration and run the script. Though the second project described in the chapter is more complex, it shows how to use both scripts and classes in your application.
This section will tell how to create a simple JavaFX with JavaFX plugin. Following the steps of this section you will be able to create a JavaFX application that runs as a standalone application and prints "Hello World!"
Once the plug-in is installed, you can create a JavaFX project.
Select File > New > Other...> JavaFX > JavaFX Project and click Next
Alternatively, if you have the JavaFX perspective activated, you can just click File > New and select JavaFX Project.
The New JavaFX project wizard will guide you through the steps required to create a new project.
Type in the project name in the Project name field first. By default the project will be added to your current workspace.
Then you need to configure your JavaFX Runtime Configuration.
Click the Configure button, then press Add to navigate to the folder where the JavaFX SDK is installed
If JavaFX SDK is already configured you will see that the Use default JavaFX runtime (currently ' current SDK version ' ) option is selected. If you wish to use other SDK version you can point to it by selecting Alternative and clicking the Configure button.
You also need to specify the type of application you are about to create in the Profile section.
Select Desktop
The Working sets option group lets you show only resources, children of resources, and parents of resources contained in the working set. The problems view, tasks view and bookmarks view can all be filtered based on a working set. When using the search facility, you can also use working sets to restrict the set of elements that are searched.
When you are done with this dialog proceed to the next one by clicking the Next button.
The Project layout option group enables you to configure where your source and class file are to be located. By default they are located in the src and bin folder respectively. You can alter the layout configuration by clicking on Configure default.. .
Click Next to set up the Java build settings. Leave everything here with default values.
Press Finish to complete the wizard's job
Now you see in your Project Explorer the project you've just created.
Now you need to add a JavaFX script to your project.
Create a new package in the src folder
Right-click on the newly created package, select New > Other...> JavaFX > JavaFX Script and click Next
Type in the file name for the script and specify the folder where it will be placed.
Notice, that you don't need to add the "fx" extension, as it's added automatically.
Click Next to open the next dialog of the wizard
The dialog gives you an option to generate a simple JavaFX Stage, you can specify the title, width and height variables of the Stage with the corresponding fields.
When the Finish button is pressed you will see the script file in the Package Explorer and the script itself in the editor.
You can now run the "Hello World" JavaFX application. What you need to do now is to configure your Run Configuration
On the Run menu click Run Configurations
In the Run Configurations dialog double-click on the JavaFX application option to create a new configuration
In this dialog you need to define the project for which you are creating the configuration, point to the .fx you've just created, make sure the JavaFX runtime is enable for the configuration. Leave the Profile and Run as fields with default values: "desktop" and "Applicaton" respectively.
Hit Run to launch the project
You will see the "Hello World!" message on your screen.
In the previous section of the guide you have learned how to create a simple JavaFX project following wizard's steps. If you are familiar with JavaFX technology it will be sufficient to start developing your application. However, if you are new to JavaFX you can take a look at JavaFX example projects.
To explore a JavaFX example you should do the following:
Navigate to File > New > Other...> Examples > JavaFX Examples (for faster navigation you can type in "JavaFX Examples" in the input field), select JavaFX Example and press Next
Configure the project
Give a meaningful name to the project
Specify the JavaFX runtime environment or use the default on if it was configured previously
Define the application type in the Profile group
Choose an example project in the Available Example list box
You can optionally add the project to a working set
Press Next to set up JRE and project layout parameters if you need to, otherwise you can hit Finish to complete the wizard
You can now have a look a the source code of the example application and run it. For more details on running a JavaFX application from Exadel JavaFX Studio please read the Launching JavaFX Project chapter of the guide.
Now we will make something more complex - a puzzle game.
Create a new project and make a package in the src folder.
Generate an empty script file, call it Game.fx (File > New > Other...> JavaFX > JavaFX Script). Configure it as it's shown in the previous Creating Simple JavaFX Project, except for the last step: do not generate any content for the script.
When you see the newly-created file in the Package Explorer double-click on the file and add the following code:
...
package com.exadel;
import javafx.ext.swing.SwingButton;
import javafx.scene.Scene;
import javafx.scene.text.Font;
import javafx.stage.Stage;
def cellSize:Number = 40;
def puz = PuzzleGrid { boxDim:3 };
def gridFont = Font
{ name: "Arial Bold"
size: 20
};
Stage
{ title: "Game"
visible: true
scene: Scene
{ content: for(idx in [0..<puz.gridSize])
{ var x:Integer = (idx mod puz.gridDim);
var y:Integer = (idx / puz.gridDim);
SwingButton
{ translateX: x * cellSize;
translateY: y * cellSize;
width: cellSize;
height: cellSize;
text: bind if(puz.grid[idx]>=1)
"{puz.grid[idx]}" else " "
font: gridFont
action: function():Void
{ var v = puz.grid[idx];
v = (v+1) mod (puz.gridDim+1);
puz.grid[idx] = v;
}
}
}
width: puz.gridDim * cellSize
height: puz.gridDim * cellSize
}
}
...
Create a class file. File > New > Other...> JavaFX > JavaFX Class
Call the file PuzzleGrid
Hit Finish
You see now the PuzzleGrid.fx file in the Package Explorer.
Double-click on the file to open it in the editor
Add the this code to the PuzzleGrid.fx file
...
package com.exadel;
public class PuzzleGrid {
public-init var boxDim:Integer = 3;
public-read def gridDim:Integer = bind boxDim*boxDim;
public-read def gridSize:Integer = bind gridDim*gridDim;
package var grid:Integer[] =
for(a in [0..<gridSize]) { 0 }
};
...
If you run the first project on the chapter you need to reconfigure your Run Configuration to set up everything for this new project, if not you need to do that from the scratch.
On the Run menu click Run Configurations , then select your current configuration or make a new one.
Select "Puzzle" project and choose the Game.fx file in the Stage field
Click the Run button to launch the project.
You should see a standalone Java application launch.
When creating a new JavaFX project the Run Configuration is set up
automatically for your project, so that you don't need to configure it manually. It
makes launching the project a very easy operation: you should click on the project to select
it and press the Run button (
) on the ToolBar.
In order to configure the default launching parameters of your application you need to click Run Configurations on the Run menu, select JavaFX Application, select your application configuration.
Another way of launching your JavaFX application with the plugin is to just select the project, right-click on it (or on script file within the project) and select Run As > Type of Application.
Moreover, having a script opened in the editor you can just call a context menu by right-clicking in the editing field and Run As > Type of Application .
If you select the Desktop profile your application can be run as:
Application
Your application is run in a separate window as a standalone application.
Applet
In case this option is selected your default browser will be pointed to an HTML file with your application as an embedded applet.
Java Web Start
The application will start using Java Web Start Technology that provides an possibility for a standalone Java software applications to be deployed with a single click over the network. Java Web Start ensures the most current version of the application will be deployed, as well as the correct version of the Java.
Exadel JavaFX Studio provides out-of-the-box an editor that can assist you in working with JavaFX projects.
Exadel JavaFX Studio provides a context dependent code assist/completion.
This feature is available for both script
and class files.
Code assist is available for these elements:
Syntax keywords
System classes
Attributes of system classes
User classes
Attributes of user classes
Alongside with code assist Exadel JavaFX Studio displays JavaFX help comments for or classes, method and attributes. The comments are shown next to the code assist box and in a box with yellow background.
JavaFX editor supports syntax highlighting that improves the readability of your code.
In order to identify where the block of code embraced with parentheses or curly braces starts or ends you need to place the cursor on the brace/parenthesis and you will see where the starting/ending brace/parenthesis is.
The editor also supports OpenOn feature that help you navigate you throughout the
project: this feature turns the objects into hyper-links when you hold CTRL and hover a
object. Your mouse pointer will become a hand (
), then you can click the link to open the file where the object is stored.
In order to have line numbers displayed on the left side of the JavaFX editor you need to right-click on left-hand border of the editor and check the Show Line Numbers option.
The Editor prevents you from making compiler error by highlighting them. The Editor verifies that you have equal number of opening and closing braces, that you typed correctly the name of the variable you had declared previously, missing semicolons and unresolved identifiers etc.
Outline view displays the structure of the file that is currently open in the editor area, and lists structural elements. Outline view can be activated (though it is displayed by default) by going to Window > Show View > Other... > General > Outline. Outline view builds a tree of the file which can be used for faster navigation and understanding of the code. Clicking on an element in the Outline view will immediately display the element in the code.
To set the JavaFX preferences you need to open the JavaFX menu tree node and reveal all it's subpages in the Preferences dialog box which you can open by clicking Windows > Preferences .
Code Style preference page allows to configure style rules like indentation and whitespace.
Table 9.1. Code Style: Indentation
| Option | Description | Default value |
|---|---|---|
| Indent Size | The number of tabs or space characters used for formatting indentation | 4 |
| Indent Type | Sets either tabs or spaces as the standard formatting indentation | Spaces Only |
You can also adjust the whitespace options.
Table 9.2. Code Style: Whitespace
| Option | Default value |
|---|---|
| Before comma | off |
| After comma | on |
| Before binary operators | on |
| After binary operators | on |
| Before assignment | on |
| After assignment | on |
On the Installed JavaFX Runtimes preferences page you can set the path to the JavaFX Runtime you intend to use in you application. You can have multiple runtimes set up.
On this page you can perform the following operations:
Add a runtime.
Click the Add button and in the Add JavaFX SDK Definition dialog specify the path to the local directory where JavaFX SDK is located.
Edit a runtime.
Select a runtime and click the Edit button. In the Edit JavaFX SDK Definition dialog you can:
Re-set the path to the local directory where JavaFX SDK is located.
Specify a name for the runtime in the Name text field.
View the JavaFX profiles.
The Script Editor enables you to adjust auto closing of such syntax elements as curly and square brackets, parentheses and quotes.
Table 9.3. Code Style: Automatically Close
| Option | Default value |
|---|---|
| "Strings" | on |
| Parentheses and [square] brackets | on |
| {Braces} | on |
Another feature that Exadle JavaFX plugin provides is to color and highlight the syntax to make code readability better.
To adjust the code coloring setting you should open the Syntax Coloring page.
The following options can be used to make your code more readable:
Color a code element
Change the font style by making it:
Bold
Italic
Strikethrough
Underlined
To alter color and font style for a paritular code element you need to:
Choose the element in the Element box.
Change the color by clicking Color button and selecting the color.
Chage the font style by checking the font options.
Hit Apply to make the changes.
Exadel JavaFX Studio provides a rich set of code snippets that you can easily use developing your application. The palette with snippets is activated once you open a JavaFX file for editing the source code and the JavaFX perspective is also enabled. Or you can activate the Snippets view by going to Window > Show View > Other ... > General > Snippets.
Adding a JavaFX element to the Editor is simple, you just need to pick the element on the palette and drag and drop it to the editor. When you release the left mouse button to drop the element a dialog box where you can set the element's parameters will appear.
For example, we can add a blue circle to the kick start application we created in the Creating Simple JavaFX Project section of the guide.
Now in the Insert Template: Circle dialog you can set the parameters of the circle.
The generated code is inserted into your JavaFX file when you press the Insert button.
Exadel JavaFX Eclipse plugin is shipped with a set of sample applications. In this chapter of the guide you will learn how to launch the applications.
It is assumed that you have the Exadel JavaFX Eclipse plugin and JavaFX SDK installed, otherwise please read the Installation chapter of the guide.
To start a sample project you need to:
Go to File > New > Other...> Examples > JavaFX Example and click Next to proceed to the next dialog of the wizard.
In the Project Name text field type in the project name for the project example. E.g. Media Box . Select a project from the Available Projects list box. For example MediaBox . Click Next .
Go through other pages of the wizard by clicking Next and configuring the project if you need to. Leaving default values is advisable.
Now you can see the project in your workspace.
The next step is to make the Run Configuration for the project. To do this you need to navigate to Run > Run Configurations . On the JavaFX Application menu node right-click and select New . Configure the project.
Name the configuration profile in the . For example, MediaBox
In the project group click Browse to select the project.
Specify the stage by clicking Browse and selecting the the stage in the Stage group. If you are configuring the MediaBox project it will be displayself.Main.
In the Running Configuration define profile and type of application ( Run as ). For example desktop and Application .
Click Apply so that the changes take effect.
Now you can run the project by hitting the Run button.
Finally you will see the sample application running.
You can get help from other plunin users on the "Exadel JavaFX Studio -- Plug-In for Eclipse" forum.
Using JavaFX and Seam/Spring with Flamingo: Exadel Flamingo project page