Java Reference
In-Depth Information
public class ScriptingExample extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
FXMLLoader fxmlLoader = new FXMLLoader();
fxmlLoader.setLocation(
ScriptingExample.class.getResource("/ScriptingExample.fxml"));
final VBox vBox = fxmlLoader.load();
Scene scene = new Scene(vBox, 600, 400);
primaryStage.setTitle("Scripting Example");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
When the ScriptingExample is run, the Scripting Example window very similar to Figure 3-4 is displayed.
You can also specify an event handler with the variable syntax:
<TextField fx:id="address"
onAction="$controller.actionHandler"
This will set the actionHandler property from the controller as the event handler of the onActionEvent .
In the controller, the actionHandler property should have the correct event handler type. For the onAction event,
the property should be like the following:
@FXML
public EventHandler<ActionEvent> getActionHandler() {
return event -> {
// handle the event
};
}
Now that we have a thorough understanding of the FXML file format, we can effectively take advantage of the
GUI editing convenience in creating FXML files.
Using JavaFX SceneBuilder
In the previous sections you have learned the fundamentals of the FXML file format. That knowledge should come in
very handy when trying to use and comprehend the JavaFX SceneBuilder tool. In this last section of the chapter, we
dive into the usages of the JavaFX SceneBuilder.
Because laying out a UI is a highly subjective, sometimes artistic endeavor, a lot depends on the application at
hand and the design sensibilities of the UI and user experience teams. We do not pretend to know the best ways of
doing UI design. So in this section, we give you a guided tour of the JavaFX SceneBuilder 2.0 itself, point out to you the
various parts of the UI designer, and discuss how to turn the knobs and switch the gears to achieve a desired result.
 
Search WWH ::




Custom Search