Exadel JavaFX Studio Guide

Version: 1.2.0


1. Introduction
2. Key Features of Exadel JavaFX Studio
3. Requirements
4. Installation
+5. Creating JavaFX Project
5.1. Creating Simple JavaFX Project
5.2. JavaFX Examples
5.3. Using a JavaFX class
+6. Launching JavaFX Project
6.1. Launching JavaFX Project: Desktop
+7. Editor Features
7.1. Code Assist
7.2. Code Highlighting
7.3. OpenOn
7.4. Line Numbering
7.5. Compiler Error Highlighting
8. Outline View
+9. Preferences for JavaFX Development
9.1. Code Style
9.2. Installed JavaFX Runtimes
9.3. Script Editor
9.4. Syntax Coloring
10. Snippets
11. JavaFX Project Examples
12. Help and Other Resources

Chapter 1. Introduction

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.

Chapter 2. Key Features of Exadel JavaFX Studio

Table 2.1. Key Features of Exadel JavaFX Studio

FeatureDescription
Multi project supportIf a project depends on some other project the plug-in can resolve the dependencies during compiling, launching and code-assist.
Code AssistCompletes your code statements faster and with more accuracy
JavaFX ExamplesExadel JavaFX Studio enables you to open a example project (standard Sun JavaFX examples) and run it from the studio
Enable JavaFX SupportExadel JavaFX Studio enables you add JavaFX capabilities to any Java project.

Chapter 3. Requirements

  • Eclipse 3.5

  • Operating System (Window, Linux)

  • Java SDK

  • JavaFX SDK

Chapter 4. Installation

  1. Install JavaFX SDK

    Download JavaFX SDK for Windows or Linux. Follow the installation instructions.

  2. 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.

  3. Start the Eclipse IDE

  4. Once Eclipse is started you can install the plugin. You need to navigate to Help > Install New Software on the main menu.

  5. Hit Add in the Available Software dialog box.

  6. 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.

    Installing the plugin

    Figure 4.1. Installing the plugin


  7. Select the Exadel JavaFX checkbox and click Next.

    Installing the plugin

    Figure 4.2. Installing the plugin


  8. In the Install Details dialog box click Next.

  9. Review and accept the terms of the license agreement and click Finish.

  10. Eclipse proceeds with the installation of the Exadel JavaFX plugin.

  11. When prompted to restart the Eclipse Platform, press Yes.

Chapter 5. Creating JavaFX Project

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.

5.1. Creating Simple JavaFX Project

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

New JavaFX Project

Figure 5.1. New JavaFX Project


Alternatively, if you have the JavaFX perspective activated, you can just click File > New and select JavaFX Project.

New Project with JavaFX Perspective Activated

Figure 5.2. New Project with JavaFX Perspective Activated


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.

New JavaFX project

Figure 5.3. New JavaFX project


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

New JavaFX project: adding JavaFX SDK

Figure 5.4. New JavaFX project: adding JavaFX SDK


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.

New JavaFX project

Figure 5.5. New JavaFX project


When you are done with this dialog proceed to the next one by clicking the Next button.

New JavaFX project

Figure 5.6. New JavaFX project


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.

New JavaFX project: Java settings

Figure 5.7. New JavaFX project: Java settings


  • Press Finish to complete the wizard's job

Now you see in your Project Explorer the project you've just created.

Demo project in the Project Explorer

Figure 5.8. Demo project in the Project Explorer


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.

New JavaFX project: adding a script

Figure 5.9. New JavaFX project: adding a script


  • 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.

New JavaFX project: generating a script

Figure 5.10. New JavaFX project: generating a script


When the Finish button is pressed you will see the script file in the Package Explorer and the script itself in the editor.

New JavaFX project

Figure 5.11. New JavaFX project


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

New JavaFX project: launching the project

Figure 5.12. New JavaFX project: launching the project


You will see the "Hello World!" message on your screen.

First JavaFX Appication

Figure 5.13. First JavaFX Appication


5.2. JavaFX Examples

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

    JavaFX Example

    Figure 5.14. JavaFX Example


  • 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

    JavaFX Example Settings

    Figure 5.15. JavaFX Example Settings


  • 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.

5.3. Using a JavaFX class

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+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

JavaFX project: adding a class

Figure 5.16. JavaFX project: adding a 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.

JavaFX project: Puzzle application

Figure 5.17. JavaFX project: Puzzle application


Chapter 6. Launching JavaFX Project

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.

Run Configuration

Figure 6.1. Run 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.

Launching a project

Figure 6.2. Launching a project


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 .

Launching a project

Figure 6.3. Launching a project


6.1. Launching JavaFX Project: Desktop

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.

Standalone Application

Figure 6.4. 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.

Applet

Figure 6.5. 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.

Chapter 7. Editor Features

Exadel JavaFX Studio provides out-of-the-box an editor that can assist you in working with JavaFX projects.

7.1. Code Assist

Exadel JavaFX Studio provides a context dependent code assist/completion.

This feature is available for both script

Code Assist for Script

Figure 7.1. Code Assist for Script


and class files.

Code Assist/Completion for Class

Figure 7.2. Code Assist/Completion for Class


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 Help Comments

Figure 7.3. JavaFX Help Comments


7.2. Code Highlighting

JavaFX editor supports syntax highlighting that improves the readability of your code.

Syntax Highlighting

Figure 7.4. Syntax Highlighting


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.

Highlighting code blocks

Figure 7.5. Highlighting code blocks


7.3. OpenOn

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.

JavaFX editor: OpenOn feature

Figure 7.6. JavaFX editor: OpenOn feature


7.4. Line Numbering

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.

Line Numbering in Editor

Figure 7.7. Line Numbering in Editor


7.5. Compiler Error Highlighting

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.

Compiler Error Highlighting

Figure 7.8. Compiler Error Highlighting


Chapter 8. Outline View

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.

Outline view

Figure 8.1. Outline view


Chapter 9. Preferences for JavaFX Development

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 .

JavaFX Preferences

Figure 9.1. JavaFX Preferences


9.1. Code Style

Code Style preference page allows to configure style rules like indentation and whitespace.

JavaFX Preferences: Code Style

Figure 9.2. JavaFX Preferences: Code Style


Table 9.1. Code Style: Indentation

OptionDescriptionDefault value
Indent SizeThe number of tabs or space characters used for formatting indentation4
Indent TypeSets either tabs or spaces as the standard formatting indentationSpaces Only

You can also adjust the whitespace options.

Table 9.2. Code Style: Whitespace

OptionDefault value
Before commaoff
After commaon
Before binary operatorson
After binary operatorson
Before assignmenton
After assignmenton

9.2. Installed JavaFX Runtimes

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.

9.3. Script Editor

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

OptionDefault value
"Strings"on
Parentheses and [square] bracketson
{Braces}on

9.4. Syntax Coloring

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.

JavaFX Preferences: Syntax Coloring

Figure 9.3. JavaFX Preferences: Syntax Coloring


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.

JavaFX Preferences: Code Style

Figure 9.4. JavaFX Preferences: Code Style


Chapter 10. Snippets

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.

Adding Circle Element

Figure 10.1. Adding Circle Element


Now in the Insert Template: Circle dialog you can set the parameters of the circle.

Some title

Figure 10.2. Some title


The generated code is inserted into your JavaFX file when you press the Insert button.

Circle JavaFX Code

Figure 10.3. Circle JavaFX Code


Chapter 11. JavaFX Project Examples

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:

  1. Go to File > New > Other...> Examples > JavaFX Example and click Next to proceed to the next dialog of the wizard.

  2. 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 .

    Project Example

    Figure 11.1. Project Example


  3. Go through other pages of the wizard by clicking Next and configuring the project if you need to. Leaving default values is advisable.

  4. Now you can see the project in your workspace.

  5. 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.

    1. Name the configuration profile in the . For example, MediaBox

    2. In the project group click Browse to select the project.

    3. 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.

    4. In the Running Configuration define profile and type of application ( Run as ). For example desktop and Application .

    5. Click Apply so that the changes take effect.

    Project Example

    Figure 11.2. Project Example


  6. Now you can run the project by hitting the Run button.

Finally you will see the sample application running.

Project Example

Figure 11.3. Project Example


Chapter 12. Help and Other Resources

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