Java Standard Edition 8 Update 40 is now upon us, and despite the “Update” designation this was a fairly massive feature release. You can find overviews at Java Source and Java Tutorials, and of course the detailed release notes. The changes I’m most interested in concern JavaFX, including accessibility support, new controls – more on the new dialogs below – and an improved native packaging mechanism to avoid requiring a preinstalled JVM.
Sadly, a quick test with my “Hello World” project showed that the native installer created via NetBeans & Inno Setup is still a hefty 38.4 MB, expanding to an enormous 158 MB once deployed! Apparently that’s because every single library is included, whether needed or not. Perhaps full modularization of the Java standard libraries in a future release will make this option viable for smaller applications.
Finally, JavaFX Dialogs
One of the most irritating functionality gaps in JavaFX has been the lack of predefined dialog classes. Showing a simple canonical “Hello World” message box involved the following steps, the same as for building a complex application window:
- Define class derived from
Stage(= JavaFX window)
- Create a
Sceneto fill the window (= client surface)
- Create a
StackPaneor similar container to hold controls
- Create a
Labelor similar text control that says “Hello World”
- Create a
Buttonthat says “OK” and has an event handler to close the dialog
- And if you want a nice icon, you need to design and package and load one, too…
At the time of this writing, creating a new JavaFX application in NetBeans 8.0.2 produces the “Hello World” class shown in Oracle’s Getting Started with JavaFX tutorial. This isn’t quite the same as above, since the button causes “Hello World” to be printed on the console rather than closing the window, but you get an idea of the required plumbing.
Java SE 8u40 finally delivers a solid dialog API, based on Jonathan Giles’ ControlsFX project. (JavaFX also got some new unrelated controls, and ControlsFX has many more controls not yet integrated with the JDK.) I don’t think Oracle has provided new dialog tutorial yet, but last year’s code.makery overview still seems to match the final API. The “Hello World” example now requires exactly one (1) line of code in the
new Alert(Alert.AlertType.INFORMATION, "Hello World").showAndWait();
Note the automatically added icon (based on
AlertType), the automatically added OK button (the default), and the two text areas for header and content text! Okay, these two areas aren’t really useful here… you can of course remove or change the boilerplate “Message” header if you’re willing to invest a few lines of code rather than a single one. The split design comes in handy for error reporting when you wish to show both a summary message and lengthy technical details.
The new API also supports dialogs with multiple buttons, and with a prebuilt drop-down box or text entry field. The dialogs can be customized, shown without predefined styling, and/or non-modally. Time to go through my JavaFX projects and replace my hand-built message boxes…
Odds & Ends
The Webkit version that powers the JavaFX
WebView class is still stuck at 537.44, released on 6 June 2013. Java 9 should eventually see a faster uptake of new Webkit releases, now that the transition to C++ 11 has been sorted out.
Oracle no longer provides binaries for Scene Builder, the interactive JavaFX GUI builder. The official page now simply points to the OpenJFX sources, much to the consternation of the OpenJFX mailing list. Happily Gluon stepped in and offers current builds for all platforms, at least for now.
java.com distribution went from bad to worse with Java SE 8u40. Not only does the 32-bit Windows version still include crapware while lacking the Server VM, Oracle has started putting crapware into the Mac OS-X distribution! So Mac as well as Windows users should now obtain their JVMs from Oracle’s Technology Network.