Installing and Setting up JavaFX for NetBeans and Eclipse IDE

Exclusive offer: get 80% off this eBook here
JavaFX 1.2 Application Development Cookbook

JavaFX 1.2 Application Development Cookbook — Save 80%

Over 60 recipes to create rich Internet applications with many exciting features

₨739.00    ₨147.80
by Vladimir Vivien | September 2010 | Cookbooks Java Web Development

This article by Vladimir Vivien, author of JavaFX 1.2 Application Development Cookbook, details the installation instructions to get your environment set up.

In this article, we will cover the following topics:

  • Installing the JavaFX SDK
  • Setting up JavaFX for the NetBeans IDE
  • Setting up JavaFX for the Eclipse IDE

(For more resources on JavaFX, see here.)

Introduction

Today, in the age of Web 2.0, AJAX, and the iPhone, users have come to expect their applications to provide a dynamic and engaging user interface that delivers rich graphical content, audio, and video, all wrapped in GUI controls with animated cinematic-like interactions. They want their applications to be connected to the web of information and social networks available on the Internet.

Developers, on the other hand, have become accustomed to tools such as AJAX/HTML5 toolkits, Flex/Flash, Google Web Toolkit, Eclipse/NetBeans RCP, and others that allow them to build and deploy rich and web-connected client applications quickly. They expect their development languages to be expressive (either through syntax or specialized APIs) with features that liberate them from the tyranny of verbosity and empower them with the ability to express their intents declaritively.

The Java proposition

During the early days of the Web, the Java platform was the first to introduce rich content and interactivity in the browser using the applet technology (predating JavaScript and even Flash). Not too long after applets appeared, Swing was introduced as the unifying framework to create feature-rich applications for the desktop and the browser. Over the years, Swing matured into an amazingly robust GUI technology used to create rich desktop applications. However powerful Swing is, its massive API stack lacks the lightweight higher abstractions that application and content developers have been using in other development environments. Furthermore, the applet's plugin technology was (as admitted by Sun) neglected and failed in the browser-hosted rich applications against similar technologies such as Flash.

Enter JavaFX

The JavaFX is Sun's (now part of Oracle) answer to the next generation of rich, web-enabled, deeply interactive applications. JavaFX is a complete platform that includes a new language, development tools, build tools, deployment tools, and new runtimes to target desktop, browser, mobile, and entertainment devices such as televisions. While JavaFX is itself built on the Java platform, that is where the commonalities end. The new JavaFX scripting language is designed as a lightweight, expressive, and a dynamic language to create web-connected, engaging, visually appealing, and content-rich applications.

The JavaFX platform will appeal to both technical designers and developers alike. Designers will find JavaFX Script to be a simple, yet expressive language, perfectly suited for the integration of graphical assets when creating visually-rich client applications. Application developers, on the other hand, will find its lightweight, dynamic type inference system, and script-like feel a productivity booster, allowing them to express GUI layout, object relationship, and powerful two-way data bindings all using a declarative and easy syntax. Since JavaFX runs on the Java Platform, developers are able to reuse existing Java libraries directly from within JavaFX, tapping into the vast community of existing Java developers, vendors, and libraries.

This is an introductory article to JavaFX. Use its recipes to get started with the platform. You will find instructions on how to install the SDK and directions on how to set up your IDE.

Installing the JavaFX SDK

The JavaFX software development kit (SDK) is a set of core tools needed to compile, run, and deploy JavaFX applications. If you feel at home at the command line, then you can start writing code with your favorite text editor and interact with the SDK tools directly. However, if you want to see code-completion hints after each dot you type, then you can always use an IDE such as NetBeans or Eclipse to get you started with JavaFX (see other recipes on IDEs). This section outlines the necessary steps to set up the JavaFX SDK successfully on your computer. These instructions apply to JavaFX SDK version 1.2.x; future versions may vary slightly.

Getting ready

Before you can start building JavaFX applications, you must ensure that your development environment meets the minimum requirements. As of this writing, the following are the minimum requirements to run the current released version of JavaFX runtime 1.2.

Minimum system requirements

How to do it...

The first step for installing the SDK on you machine is to download it from http://javafx.com/downloads/. Select the appropriate SDK version as shown in the next screenshot.

Once you have downloaded the SDK for your corresponding system, follow these instructions for installation on Windows, Mac, Ubuntu, or OpenSolaris.

Installation on Windows

  1. Find and double-click on the newly downloaded installation package (.exe file) to start.
  2. Follow the directions from the installer wizard to continue with your installation.

Make sure to select the location for your installation. The installer will run a series of validations on your system before installation starts. If the installer finds no previously installed SDK (or the incorrect version), it will download a SDK that meets the minimum requirements (which lengthens your installation).

Installation on Mac OS

  1. Prior to installation, ensure that your Mac OS meets the minimum requirements.
  2. Find and double-click on the newly downloaded installation package (.dmg file) to start.
  3. Follow the directions from the installer wizard to continue your installation.
  4. The Mac OS installer will place the installed files at the following location:/Library/Frameworks/JavaFX.framework/Versions/1.2.

Installation on Ubuntu Linux and OpenSolaris

  1. Prior to installation, ensure that your Ubuntu or OpenSolaris environment meets the minimum requirements.
  2. Locate the newly downloaded installation package to start installation. For Linux, the file will end with *-linux-i586.sh. For OpenSolaris, the installation file will end with *-solaris-i586.sh.
  3. Move the file to the directory where you want to install the content of the SDK.
  4. Make the file executable (chmod 755) and run it. This will extract the content of the SDK in the current directory.
  5. The installation will create a new directory, javafx-sdk1.2, which is your JavaFX home location ($JAVAFX_HOME).
  6. Now add the JavaFX binaries to your system's $PATH variable, (export PATH=$PATH:$JAVAFX_HOME/bin).

When your installation steps are completed, open a command prompt and validate your installation by checking the version of the SDK.

$> javafx -version

$> javafx 1.2.3_b36

You should get the current version number for your installed JavaFX SDK displayed.

How it works...

Version 1.2.x of the SDK comes with several tools and other resources to help developers get started with JavaFX development right away.

The major (and more interesting) directories in the SDK include:

Setting up JavaFX for the NetBeans IDE

The previous recipe shows you how to get started with JavaFX using the SDK directly. However if you are more of a syntax-highlight, code-completion, click-to-build person, you will be delighted to know that the NetBeans IDE fully supports JavaFX development. JavaFX has first-class support within NetBeans, with functionalities similar to those found in Java development including:

  • Syntax highlighting
  • Code completion
  • Error detection
  • Code block formatting and folding
  • In-editor API documentation
  • Visual preview panel
  • Debugging
  • Application profiling
  • Continuous background build
  • And more...

This recipe shows how to set up the NetBeans IDE for JavaFX development. You will learn how to configure NetBeans to create, build, and deploy your JavaFX projects.

Getting ready

Before you can start building JavaFX applications in the NetBeans IDE, you must ensure that your development environment meets the minimum requirements for JavaFX and NetBeans (see previous recipe Installing the JavaFX SDK for minimum requirements). Version 1.2 of the JavaFX SDK requires NetBeans version 6.5.1 (or higher) to work properly.

How to do it...

As a new NetBeans user (or first-time installer), you can download NetBeans and JavaFX bundled and ready to use. The bundle contains the NetBeans IDE and all other required JavaFX SDK dependencies to start development immediately. No additional downloads are required with this option.

To get started with the bundled NetBeans, go to http://javafx.com/downloads/ and download the NetBeans + JavaFX bundle as shown in the next screenshot (versions will vary slightly as newer software become available).

JavaFX 1.2 Application Development Cookbook Over 60 recipes to create rich Internet applications with many exciting features
Published: August 2010
eBook Price: ₨739.00
Book Price: ₨1,232.00
See more
Select your format and quantity:

Read more about this book

(For more resources on JavaFX, see here.)

NetBeans installation on Windows

  1. Prior to installation, ensure that your Windows environment meets the minimum requirements (see recipe Installing the JavaFX SDK).
  2. Find and double-click on the newly downloaded installation package (.exe file) to start.
  3. Follow the instructions from the installer to install NetBeans (default install location C:\Program Files\NetBeans {version-number}).

Installation on Mac OS

  1. Prior to installation, ensure that your Mac OS meets the minimum requirements (see the recipe Installing the JavaFX SDK).
  2. Find and double-click on the newly downloaded installation package (.dmg file) to start.
  3. Follow the directions from the installer to install NetBeans (default install location:Macintosh HD/Applications/NetBeans/NetBeans {version-number}).

Installation on Ubuntu Linux and OpenSolaris

Prior to installation, ensure that your Ubuntu or OpenSolaris installation meets the minimum requirements (see recipe Installing the JavaFX SDK).

  1. Find the newly downloaded installation package: for Linux, the file will end in *-linux-i586.sh; for OpenSolaris, the file will end in *-solaris-i586.sh.
  2. Make the file executable, and run it.
  3. Follow the directions from the installer to install NetBeans (default location: $HOME/netbeans-{version-number})

Now that NetBeans is ready, lets create a quick "Hello World" so you can test your JavaFX NetBeans installation. To get started, select New Project from the File menu.

When the New Project wizard opens, select JavaFX from the Categories list and click on the Next button. Enter the location where the project will be saved, and click on the Next button. You will end up with a shell of a JavaFX application ready to run. Update the title and content properties as highlighted in the next code snippet. You can see the full code listing at ch01/source-code/src/hello/HelloJavaFX.fx.

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.text.Font;

Stage {
title: "Hello JavaFX"
width: 250
height: 80
scene: Scene {
content: [
Text {
font : Font {size : 16}
x: 10
y: 30
content: "Hello World!"
}
]
}

When you run the code (right-click on the project and select Run Project), NetBeans automatically handles the compilation, packaging, and execution of the code in the JavaFX runtime for you, as shown in the next screenshot.

How it works...

When you download the bundled NetBeans + JavaFX SDK, it comes with everything needed to start developing JavaFX. The bundle will install the NetBeans IDE and will also automatically download and install the NetBeans plugins required for JavaFX development including the latest SDK. Be aware that if you have downloaded the SDK separately (as explained in the recipe Installing the JavaFX SDK), you will end up with two copies of the SDK on your local machine.

There's more...

If you already use NetBeans, you can make your IDE JavaFX-ready by downloading the necessary plugins. The plugins contain the JavaFX SDK and all required dependencies to start your JavaFX development immediately, no other download is required. Note that your NetBeans must meet the minimum requirements for JavaFX to work properly (see previous recipe).

Download JavaFX NetBeans plugin

  1. Open the Plugins management window (Tools | Plugins) in NetBeans and click on the Available Plugins tab.
  2. Do a search for javafx to filter the available plugins list as shown in the previous screenshot.
  3. Select the JavaFX Kit and the JavaFX SDK for {Your OS name} bundles as shown in the previous screenshot, and then click on the Install button.
  4. Follow the instructions from the NetBeans installer to install the selected plugins.
  5. Make sure to select Restart IDE Now to complete the installation.

See also

  • Installing the JavaFX SDK
  • Setting up JavaFX for the Eclipse IDE
JavaFX 1.2 Application Development Cookbook Over 60 recipes to create rich Internet applications with many exciting features
Published: August 2010
eBook Price: ₨739.00
Book Price: ₨1,232.00
See more
Select your format and quantity:

Read more about this book

(For more resources on JavaFX, see here.)

Setting up JavaFX for the Eclipse IDE

As of JavaFX version 1.2, Sun Microsystems the name (will be Oracle by the time you read this) officially released a fully functional plugin to support development in the Eclipse IDE. While the Eclipse plugin came after NetBean's, it still packs an invaluable set of functionalities for developers who feel more comfortable working in Eclipse, including:

  • Project creation wizard and templates
  • Syntax highlighting
  • Code completion
  • Error detection
  • Code block formatting and folding
  • In-editor API documentation
  • Debugging
  • Continuous background build
  • And more...

This recipe shows how to set up the Eclipse IDE for JavaFX development. You will learn how to configure Eclipse and the JavaFX 1.2 plugin.

Getting ready

Before you can start building JavaFX applications in the Eclipse IDE, you must ensure that your development environment meets the minimum requirements for JavaFX 1.2, which requires Eclipse 3.4 (Ganamede) for Java EE developers (or higher). To get the Eclipse plugin to work properly, ensure that you have downloaded and configured the Java JDK and the JavaFX SDK (see the recipe Installing the JavaFX SDK for details).

How to do it...

As with anything else in Eclipse, JavaFX support comes in the form of a plugin. You have to download and configure the plugin to work with your previously installed local JavaFX SDK prior to building your applications. To get started, do the following:

  1. Select Software Updates from the Help menu to open the Plugins management window.
  2. Click on the Available Software tab.
  3. Add the site http://javafx.com/downloads/eclipse-plugin/ as the plugin site.

  4. Select the JavaFX site, as shown in the previous screenshot, then click on Install to continue.
  5. Follow the instructions of the plugin wizard.
  6. Accept the terms of the license, and make sure to restart the Eclipse IDE when prompted.

Now that you have Eclipse setup with JavaFX, it makes sense to create a quick Hello World application in Eclipse to test the installation.

To get started, select New from the File menu (you may have to select Other if JavaFX is not listed as a project type).

You must have the SDK installed and configured prior to creating your first application (see recipe Installing the JavaFX SDK).

  1. When presented with the new project wizard, select JavaFX Project and click on the Next button.
  2. Then, provide the project's name (HelloWorld), location, JRE version, and type (default is Desktop) to continue with the project's creation.
  3. Click on the Next button and select a project template (which is a based on pre-existing sample code). Select the Empty Project template and click on the Finish button.
  4. The wizard will complete the project creation, and you should have a project shell ready for you to start coding.
  5. To continue, create a new code package (right-click on the project source directory, and select New | Package), and name the package hello.
  6. Next, right-click on the newly created source package and select New | Empty JavaFX Script from the context menu, and name itHelloJavaFX.fx.
  7. This will do exactly what it says, which is to create an empty code window. Notice, however, that the editor comes with several code snippets that you can reuse in your own code.

  8. In the Snippets window, shown in the previous screenshot, click on Applications and double-click on Stage. This will bring up a template editor. Accept the default values and continue.

Edit the sample code by adding the highlighted portion. You can see the full code listing at ch001/source-code/src/hello/HelloJavaFX.fx.

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.text.Font;

Stage {
title: "Hello JavaFX"
scene: Scene {
width: 250
height: 200
content: [
Text {
font : Font {size : 16}
x: 10
y: 30
content: "Hello World!"
}
]
}

Once you have updated the code, right-click on the project and select Run As | JavaFX Application. If you are running the application for the first time, you will be prompted to select the application's targeted profile and the main class.

How it works...

Support for JavaFX in Eclipse comes as separate plugin download. When you install the plugin, it adds the capabilities of JavaFX development to your IDE. Unlike the NetBeans plugin, as of version 1.2, the SDK is not available as part of the plugin download. You must download and have the SDK installed on your workstation. When the plugin is installed, it will look for the SDK on your machine.

See also

  • Installing the JavaFX SDK
  • Setting up JavaFX for the NetBeans IDE

Summary

In this article we covered the installation instructions to get your environment set up.


Further resources on this subject:


About the Author :


Vladimir Vivien

Vladimir Vivien is a software engineer living in the United States. Past and current experiences include development in Java and .Net for industries including publishing, financial, and healthcare where he worked with a number of varied technologies including user-facing GUI frontends and backend mid-tiers. Vladimir enjoys taking part in open source projects and has contributed JmxBuilder to the Groovy project and is an author of other projects such as JmxLogger. Beside JavaFX, he has a wide range of technology interests including Java, OSGi, Scala, and anything else that runs on the JVM.

Books From Packt


NetBeans Platform 6.9 Developer's Guide
NetBeans Platform 6.9 Developer's Guide

MooTools 1.2 Beginner's Guide
MooTools 1.2 Beginner's Guide

YUI 2.8: Learning the Library
YUI 2.8: Learning the Library

Learning Ext JS 3.0
Learning Ext JS 3.0

Java EE 6 with GlassFish 3 Application Server
Java EE 6 with GlassFish 3 Application Server

Tomcat 6 Developer's Guide
Tomcat 6 Developer's Guide

Spring Persistence with Hibernate
Spring Persistence with Hibernate

EJB 3.0 Database Persistence with Oracle Fusion Middleware 11g
EJB 3.0 Database Persistence with Oracle Fusion Middleware 11g


Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software