Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

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

Practical JavaFX 2, Part 1: Architecture of a Swing-based notepad

How will Swing JPad's UI features map to JavaFX 2.0?

  • Print
  • Feedback

Page 2 of 6

  • Java's builders replace JavaFX Script's script initialization blocks. A builder is a Java class whose methods are designed so that you can chain together method calls.
  • Change listeners replace replace triggers.
  • Observable lists replace sequences.
  • Single abstract method (SAM) types replace function types. A SAM type is a single-method interface or abstract class -- the abstract class's method is abstract. When Java 8 arrives, we'll be able to use lambda expressions to more concisely work with SAM types.
  • Properties based on an expanded and improved version of the JavaBeans model have been introduced to support binding. Whereas JavaFX Script enabled binding to any variable, JavaFX 2.0 only allows binding to properties.

Further changes to JavaFX 2 include the following:

  • Experimental menu, toolbar, and tree UI controls introduced in JavaFX 1.3.1 are now standard. JavaFX 2 also features new table and HTML-editor controls along with standard file dialogs. All controls can be skinned via CSS3+.
  • A new web-view component based on WebKit makes it possible to embed a web browser (with JavaScript and Document Object Model support) into Java applications.
  • JavaFX 2 supports FXML, a scriptable, XML-based markup language for constructing UIs. FXML replaces the former JavaFX Script-oriented FXD (JavaFX Data) format.
  • JavaFX application deployment has been improved. You can now create custom preloaders (specialized JavaFX applications extending the javafx.application.Preloader class) to enhance application loading and startup.
  • JavaFX 2's application architecture has been improved to simplify the organization of applications that will run in multiple deployment contexts. New APIs enable applications to detect and interact with their deployment environments.
  • A new platform architecture based on a hardware-accelerated graphics pipeline (Prism) and windowing toolkit (Glass) improves the performance of JavaFX 2 applications. When combined with Java ME, it should help in migrating JavaFX applications to mobile and tablet devices.

Is JavaFX 2 production ready?

As you read this article, consider the following questions:

  • Is JavaFX 2 a production-ready platform, as Oracle claims?
  • Are there notable advantages to programming in JavaFX versus Swing?

I'll share my answers to these questions at the end of Part 3. You'll also be invited to share your viewpoint in the article's discussion forum.

Introducing JPad

JPad is a Java-based text editor application that's very similar to Windows XP's Notepad program. As with Notepad, JPad lets you open a document file, make changes to its text, and save your changes to the currently open file or a new document file. You can also undo changes, interact with the clipboard through cut/copy/paste operations, and perform other tasks. Figure 1 is a screenshot of JPad's UI.

Figure 1. A screenshot of Swing JPad (click to enlarge)

Figure 1 reveals a simple UI that consists of a menu bar, a scrollable text area, and a status bar. The menu bar displays File, Edit, Format, and Help menus; the text area displays the current document and lets you make changes; and the status bar displays a default message or the help text that's associated with the currently selected menu. Note that the Cut and Copy functions are disabled until text is selected.

  • Print
  • Feedback

Resources

More from JavaWorld

  • Find more of Jeff's writing in Java Tutor, his blog on JavaWorld.
  • See the JavaWorld Site Map for a complete listing of research centers focused on client-side, enterprise, and core Java development tools and topics.
  • JavaWorld's Java Technology Insider is a podcast series that lets you learn from Java technology experts on your way to work.