Java Reference
In-Depth Information
Packages > <default package> node (Fig. 25.6). If you specified a package name for the
app class in Fig. 25.5, then that package's name will appear rather than <default package> .
Expanded node
Collapsed node
Fig. 25.6 | NetBeans Projects window.
NetBeans creates and opens three files for a JavaFX FXML Application project:
Welcome.fxml —This file contains the FXML markup for the GUI. By default,
the IDE creates a GUI containing a Button and a Label .
Welcome.java —This is the main class that creates the GUI from the FXML file
and displays the GUI in a window.
WelcomeController.java —This is the class in which you'd define the GUI's
event handlers that allow the app to respond to user interactions with the GUI.
In Section 25.5, when we present an app with event handlers, we'll discuss the main app
class and the controller class in detail. For the Welcome app, you will not edit any of these
files in NetBeans, so you can close them. You do not need the WelcomeController.java
file in this app, so you can right click the file in the Projects window and select Delete to
remove it. Click Yes in the confirmation dialog to delete the file.
25.4.3 Adding an Image to the Project
One way to use an image in your app is to add its file to the project, then display it on an
ImageView . The bug.png image you'll use for this app is located in the images subfolder
of this chapter's examples folder. Locate the images folder on your file system, then drag
bug.png onto the project's <default package> node to add the file to the project.
25.4.4 Opening JavaFX Scene Builder from NetBeans
You'll now open JavaFX Scene Builder so that you can create this app's GUI. To do so,
right click Welcome.fxml in the Projects window, then select Open to view the FXML file
in Scene Builder (Fig. 25.7).
Deleting the Default Controls
The FXML file provided by NetBeans contains a default GUI consisting of a Button con-
trol and a Label control. The Welcome app will not use these default controls, so you can
delete them. To do so, click each in the content panel (or in the Hierarchy window at the
bottom-left of Scene Builder's window), then press the Backspace or Delete key. In each
case, Scene Builder displays the warning “ Some components have an fx:id. Do you really
want to delete them? ”. This means that there could be Java code in the project that refers
 
 
 
Search WWH ::




Custom Search