The JavaFX SceneBuilder Tool
Oracle recently released a preview of a new tool to help with GUI layout for JavaFX 2.x applications, called the JavaFX SceneBuilder. It's available for Windows, Mac OS X, and Linux, and you can download it here. It's available on all of these platforms because it's built on Java itself.
More Insights
White Papers
- Unified Communications Buyer's Guide
- Real World Considerations for Implementing Desktop Virtualization eBook
Reports
More >>Webcasts
- Rising to the challenge of RMORSA - leveraging existing capabilities and building new ones
- Data Center Performance: Optimization Secrets Revealed
It sports a very clean, easy-to-use interface, which is consistent with the JavaFX mantra. Here's the screen as greeted when you start the application:
You can then add layouts, shapes, and controls to the canvas, position and resize them as you please, and save when you're done. To do so, simply drag-and-drop from the available components in the list along the left, into the correct area of your canvas in the middle. The result is an FXML file, which is an XML-based layout structure used by JavaFX, and combined with a CSS file, to form the skinned GUI of your application.
Bind Code to GUI
If you save this file along with the source code for your JavaFX project in NetBeans, you can bind elements of your GUI in SceneBuilder, along with associated events and actions, with your code. To do so, you need to have the elements defined in your code, usually within a controller class, select the relevant component in SceneBuilder, and set the Controller Class in the Document section along the right-hand navigation (see figure below).
You define the appropriate elements in your code as such:
package mycooljavafxapp;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
public class AppController implements Initializable {
@FXML
Button helloBtn;
@Override
public void initialize(URL url, ResourceBundle rb) {
}
public void onHelloButton(ActionEvent event) {
System.out.println("Hello, World!");
}
}
Then bind to your controls as shown below:
Next, you can bind a control's event by selecting the control, then the proper event method from the drop-down list within the Events section of the tool, as shown below:
You can find more information on JavaFX and the JavaFX SceneBuilder here, along with a Getting Started Guide.
Happy coding!
EJB

