Using NetBeans to Build a JavaFX FXML Application
When teams across Sydney and Melbourne build enterprise desktop tooling, they often reach for Java because the talent pool is strong, the runtime is stable on both Windows and macOS workstations, and the libraries are well documented. JavaFX paired with FXML gives those teams a clean separation between presentation and logic, which is exactly the kind of structure that keeps a multi-year codebase readable. NetBeans remains one of the friendliest IDEs for this kind of work, with first-class JavaFX support, Scene Builder hooks, and a project wizard that handles module configuration without forcing you to wrestle with command-line flags.
The workflow below walks through a small but realistic desktop form, complete with a JDBC connection to an external data source. It assumes you already have a recent NetBeans build with JDK 17 or newer installed, and that Scene Builder is available either as a standalone tool or as a NetBeans plugin. If you are importing code from another tool, the guide on generate a project from an existing source folder covers the import side of things before you start layering FXML on top.
Setting up the NetBeans project for JavaFX
Open NetBeans and choose File → New Project. From the JavaFX category, select JavaFX FXML Application, give the project a name such as client-intake, and pick a folder that lives somewhere sensible. For many Brisbane-based freelancers that means a folder under their Documents directory rather than inside iCloud or OneDrive, which can cause file-locking issues during builds. NetBeans will scaffold a Main class, an FXML file, a controller, and the usual application.css stylesheet.
Once the project is generated, right-click the Libraries node and confirm that the JavaFX SDK is registered. If your organisation uses an internal artifact repository, swap the default public Maven coordinates for your mirror at this point so the next clean build does not stall on a flaky public proxy. From there you can run the sample, see the empty AnchorPane appear in a window, and start replacing placeholder content with your own layout.
Crafting the FXML layout
The heart of the workflow is the FXML file. Open PrimaryController.fxml from the project tree and switch to the Source view if NetBeans has opened it in design mode. The FXML vocabulary is short: <AnchorPane> and <VBox> give you layout containers, <Label> and <TextField> give you leaf widgets, and fx:id attributes tie those widgets back to fields in the controller. Scene Builder becomes invaluable here because it lets you drag a split pane into place, resize it, and preview the result without writing a single line of XML by hand.
A common pattern in Australian healthcare and billing software is a left-side navigation list paired with a right-side detail form. Build it with a <SplitPane> containing a <ListView> and a <GridPane>, then set fx:controller on the root to point at the fully qualified controller class. Many Australian design teams discover that a layout which looks fine on a 4K monitor feels cramped on the 13-inch laptops consultants travel with, so preview at standard zoom early.
| Approach | Separation of concerns | Tooling in NetBeans | Best fit |
|---|---|---|---|
| Pure programmatic JavaFX | Low — UI code mixed with logic | Basic syntax highlighting only | Quick prototypes, throwaway demos |
| FXML with a controller class | High — markup separate from behaviour | Full Scene Builder integration | Maintainable business applications |
| FXML with an FXMLLoader factory | Very high — multiple controllers per view | Full integration, requires discipline | Large enterprise suites |
| CSS-only styling layered on FXML | Medium — visuals separate, logic tied to controller | Native CSS editor in NetBeans | Branded client-facing tools |
Writing the controller and handling user input
With the FXML in place, open the controller class and add @FXML annotations to fields whose fx:id matches an element in the markup. NetBeans will flag unresolved references in the editor as you type, which is one of the small but meaningful reasons developers in Perth and Adelaide still pick NetBeans over lighter editors when they are working on FXML-heavy projects. Wire up button clicks with simple @FXML void methods, and keep the controller focused on view logic — anything that touches a database or a remote service should delegate to a service class.
A useful Australian-specific touch is to plan for Locale.ENGLISH formatting of dates and currency even though your users may expect DD/MM/YYYY in their reports. The DateTimeFormatter and NumberFormat classes make this trivial, and keeping that formatting inside the controller's initialize() method means the rest of the application can stay locale-agnostic. If your application is destined for a government client, also remember to log user actions with timestamps in UTC so that audit trails remain consistent across states.
Connecting to a data source with JDBC
Few real applications live entirely on the client, so the next step is to pull live records into your form. NetBeans ships with a Services tab where you can register drivers and connection profiles under the Databases node. Once a profile exists, you can copy its URL into your service class and let JDBC hand back a ResultSet. The NetBeans Blog has a deeper walkthrough on how to manage database connections with JDBC for teams that want to share profiles across machines without checking passwords into version control.
On submit, bind the controller's text fields to a small DTO, pass it to your service, and execute a parameterised PreparedStatement. String concatenation in queries has tripped up enough Melbourne fintech teams that most engineering managers treat it as a code-review blocker. If your data source sits behind a corporate firewall, configure NetBeans to run with the appropriate SOCKS proxy arguments so debugging sessions do not silently fail.
Building, testing and packaging the application
Before handing the project over, run a clean build and execute the application's JUnit suite from the Run menu. NetBeans produces a dist folder containing a shaded JAR plus a lib directory. For internal distribution, that pair is usually enough — many Australian consultancies still ship JavaFX apps as zipped folders because the runtime is already installed on every workstation they manage.
For wider distribution, consider packaging with jpackage so end users receive a native .dmg or .exe rather than a script they have to run themselves. Whichever route you choose, document the minimum JDK version in a README.md at the project root and include a one-paragraph note about how to launch the application on Windows, macOS and Linux. That single paragraph saves more support emails than any amount of refactoring.
Practical habits that keep the project healthy
- Commit the FXML files as plain text so diffs are readable in pull requests.
- Keep the controller focused on view glue; push business logic into service classes.
- Use parameterised queries everywhere a user input touches SQL.
- Register your Scene Builder path in NetBeans once and forget about it.
- Add a smoke test that loads the main FXML file to catch broken references early.
- Pin the JDK version in
nbactions.xmlso every developer builds against the same target.