Book Image

JavaFX 1.2 Application Development Cookbook

By : Vladimir Vivien
Book Image

JavaFX 1.2 Application Development Cookbook

By: Vladimir Vivien

Overview of this book

JavaFX Script enables you to easily create rich Internet applications by embedding multimedia components. Although you can create stylish Internet applications by modifying these default components, even advanced users find it challenging to create impressive feature-rich Internet applications with JavaFX. Also, there are limited JavaFX components to work with and by default these components don't look visually appealing.This book explores limitless possibilities to style your application by coding JavaFX components to display your content in a more appealing fashion. The recipes in this book will help you to create customized JavaFX components with which you can make modern, feature-rich applications.First, you will be introduced to the JavaFX SDK and other development tools available to help you be productive during development. You will create an application in JavaFX by arranging complex graphical components (and non-graphical libraries) with simplified declarative constructs. You will then explore the fun side of JavaFX by using transformation techniques to manipulate the location and dimensions of objects. The next chapter is about the GUI components that are available in the framework, which provide a high level of interactivity. You will learn how to use the media component to play media content. Then we will access data and manipulate data locally or remotely. You will explore many deployment options and integration tips and tricks to take advantage of runtime contexts. Finally, you will interact with pure Java code to read and write files in JavaFX and to establish interactions with computing platforms.
Table of Contents (18 chapters)
JavaFX 1.2 Application Development Cookbook
Credits
About the Author
About the Reviewers
Preface
Mobile JavaFX
JavaFX Composer
JavaFX Products and Frameworks
Best Practices for Development
Best Practices for Deployment

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

NetBeans installation on Windows

  1. 1. Prior to installation, ensure that your Windows environment meets the minimum requirements (see recipe Installing the JavaFX SDK).

  2. 2. Find and double-click on the newly downloaded installation package (.exe file) to start.

  3. 3. Follow the instructions from the installer to install NetBeans (default install location C:\Program Files\NetBeans {version-number}).

Installation on Mac OS

  1. 1. Prior to installation, ensure that your Mac OS meets the minimum requirements (see the recipe Installing the JavaFX SDK).

  2. 2. Find and double-click on the newly downloaded installation package (.dmg file) to start.

  3. 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. 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. 2. Make the file executable, and run it.

  3. 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. 1. Open the Plugins management window (Tools | Plugins) in NetBeans and click on the Available Plugins tab.

  2. 2. Do a search for javafx to filter the available plugins list as shown in the previous screenshot.

  3. 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. 4. Follow the instructions from the NetBeans installer to install the selected plugins.

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