Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Upgrading a Swing-based app to JavaFX gives you access to the modern UI features of a RIA framework, as well as the ability to easily deploy your application in multiple environments. In this article, you'll see for yourself how a Swing-based notepad application's basic UI architecture maps to JavaFX. There are some adjustments involved, but the trade-off in rich UI features and flexible deployment could be worth it.
The first part of this article introduced a Swing-based notepad application. Now I'll introduce its JavaFX counterpart, JPadFX. We'll start with the basic UI architecture of JPadFX, which maps to the features developed for the Swing JPad: border pane, menu system, scene, and stage. I'll also discuss observable lists, which don't map to a Swing counterpart. Finally, I'll introduce JPadFX's event-handling architecture and explain how it differentiates from the approach used in the Swing-based app.
Note that Part 2 focuses on the basic, and essential, features of a JavaFX notepad application. Part 3 introduces the more advanced features of dialog boxes, the clipboard, and drag-and-drop support.
JPadFX is the JavaFX equivalent of the Swing-based JPad application that I introduced in the first part. JPadFX is more or less identical to the Swing-based notepad, as you can see in Figure 1, a screenshot of JPadFX's user interface.
Note that unlike the Swing-based notepad, JPadFX shows no undo function on the UI. JavaFX doesn't support an undo function, and I chose not to introduce a legacy UI dependency into the application. As JavaFX matures the need for such dependencies (or doing without them) will decrease.
You can download the source files for JPadFX anytime: JPad.java, About.java, Alert.java, AreYouSure.java, and the resource file icon.png. After extracting these files to your current directory, execute the following commands to compile JPadFX.java and the other source files, and run JPadFX. The third command tells JPadFX to open and display the contents of JPadFX.java:
javac -cp "C:\Program Files\Oracle\Javafx 2.0 SDK\rt\lib\jfxrt.jar";. JPadFX.java
java -cp "C:\Program Files\Oracle\Javafx 2.0 SDK\rt\lib\jfxrt.jar";. JPadFX
java -cp "C:\Program Files\Oracle\Javafx 2.0 SDK\rt\lib\jfxrt.jar";. JPadFX JPadFX.java
Note that the above commands assume a Windows platform and that you have installed the JavaFX 2.0.2 SDK to C:\Program Files\Oracle\JavaFX 2.0 SDK. This home directory's rt subdirectory contains a lib subdirectory. That subdirectory contains jfxrt.jar, which in turn contains JavaFX API class files. I've appended a dot (representing the current directory) to javac's classpath so that this tool can locate the other source files.
More from JavaWorld