This chapter provides an overview of the types of applications you can build using JavaFX APIs, where to download the JavaFX libraries, and a high level information about the key JavaFX features being delivered.

JavaFX is a set of graphics and media packages that enables developers to design, create, test, debug, and deploy rich client applications that operate consistently across diverse platforms.

JavaFX Applications

Since the JavaFX library is written as a Java API, JavaFX application code can reference APIs from any Java library. For example, JavaFX applications can use Java API libraries to access native system capabilities and connect to server-based middleware applications.

The look and feel of JavaFX applications can be customized. Cascading Style Sheets (CSS) separate appearance and style from implementation so that developers can concentrate on coding. Graphic designers can easily customize the appearance and style of the application through the CSS. If you have a web design background, or if you would like to separate the user interface (UI) and the back-end logic, then you can develop the presentation aspects of the UI in the FXML scripting language and use Java code for the application logic. If you prefer to design UIs without writing code, then use JavaFX Scene Builder. As you design the UI, Scene Builder creates FXML markup that can be ported to an Integrated Development Environment (IDE) so that developers can add the business logic.

Availability

The JavaFX APIs are available as a fully integrated feature of the Java SE Runtime Environment (JRE) and the Java Development Kit (JDK ). Because the JDK is available for all major desktop platforms (Windows, Mac OS X, and Linux), JavaFX applications compiled to JDK 7 and later also run on all the major desktop platforms. Support for ARM platforms has also been made available with JavaFX 8. JDK for ARM includes the base, graphics and controls components of JavaFX.

The cross-platform compatibility enables a consistent runtime experience for JavaFX applications developers and users. Oracle ensures synchronized releases and updates on all platforms and offers an extensive support program for companies that run mission-critical applications.

On the JDK download page, you can get a zip file of JavaFX sample applications. The sample applications provide many code samples and snippets that show by example how to write JavaFX applications. See “How Do I Run a Sample Application?” for more information.

Key Features

The following features are included in JavaFX 8 and later releases. Items that were introduced in JavaFX 8 release are indicated accordingly:

  • Java APIs. JavaFX is a Java library that consists of classes and interfaces that are written in Java code. The APIs are designed to be a friendly alternative to Java Virtual Machine (Java VM) languages, such as JRuby and Scala.
  • FXML and Scene Builder. FXML is an XML-based declarative markup language for constructing a JavaFX application user interface. A designer can code in FXML or use JavaFX Scene Builder to interactively design the graphical user interface (GUI). Scene Builder generates FXML markup that can be ported to an IDE where a developer can add the business logic.
  • WebView. A web component that uses WebKitHTML technology to make it possible to embed web pages within a JavaFX application. JavaScript running in WebView can call Java APIs, and Java APIs can call JavaScript running in WebView. Support for additional HTML5 features, including Web Sockets, Web Workers, and Web Fonts, and printing capabilities have been added in JavaFX 8. See Adding HTML Content to JavaFX Applications.
  • Swing interoperability. Existing Swing applications can be updated with JavaFX features, such as rich graphics media playback and embedded Web content. The SwingNode class, which enables you to embed Swing content into JavaFX applications, has been added in JavaFX 8. See the SwingNode API javadoc and Embedding Swing Content in JavaFX Applications for more information.
  • Built-in UI controls and CSS. JavaFX provides all the major UI controls that are required to develop a full-featured application. Components can be skinned with standard Web technologies such as CSS. The DatePicker and TreeTableView UI controls are now available with the JavaFX 8 release. See Using JavaFX UI Controls for more information. Also, the CSS Styleable* classes have become public API, allowing objects to be styled by CSS.
  • Modena theme**.** The Modena theme replaces the Caspian theme as the default for JavaFX 8 applications. The Caspian theme is still available for your use by adding the setUserAgentStylesheet(STYLESHEET_CASPIAN) line in your Application start() method. For more information, see the Modena blog at fxexperience.com
  • 3D Graphics Features. The new API classes for Shape3D (Box, Cylinder, MeshView, and Sphere subclasses), SubScene, Material, PickResult, LightBase (AmbientLight and PointLight subclasses), and SceneAntialiasing have been added to the 3D Graphics library in JavaFX 8. The Camera API class has also been updated in this release. For more information, see the Getting Started with JavaFX 3D Graphics document and the corresponding API javadoc for javafx.scene.shape.Shape3D, javafx.scene.SubScene, javafx.scene.paint.Material, javafx.scene.input.PickResult, and javafx.scene.SceneAntialiasing.
  • Canvas API. The Canvas API enables drawing directly within an area of the JavaFX scene that consists of one graphical element (node).
  • Printing API. The javafx.print package has been added in Java SE 8 release and provides the public classes for the JavaFX Printing API.
  • Rich Text Support. JavaFX 8 brings enhanced text support to JavaFX, including bi-directional text and complex text scripts, such as Thai and Hindu in controls, and multi-line, multi-style text in text nodes.
  • Multitouch Support. JavaFX provides support for multitouch operations, based on the capabilities of the underlying platform.
  • Hi-DPI support. JavaFX 8 now supports Hi-DPI displays.
  • Hardware-accelerated graphics pipeline. JavaFX graphics are based on the graphics rendering pipeline (Prism). JavaFX offers smooth graphics that render quickly through Prism when it is used with a supported graphics card or graphics processing unit (GPU). If a system does not feature one of the recommended GPUs supported by JavaFX, then Prism defaults to the software rendering stack.
  • High-performance media engine. The media pipeline supports the playback of web multimedia content. It provides a stable, low-latency media framework that is based on the GStreamer multimedia framework.
  • Self-contained application deployment model. Self-contained application packages have all of the application resources and a private copy of the Java and JavaFX runtimes. They are distributed as native installable packages and provide the same installation and launch experience as native applications for that operating system.

JavaFX是一组图形和媒体的应用包,开发人员能通过JavaFx设计、创建、测试、调试并且部署在不同平台上能够运行的客户端应用程序。

##JavaFX应用程序

JavaFX库是作为JavaAPI编写的,所以JavaFX应用程序代码可以引用来自任何Java原生库的API。例如,JavaFX应用程序可以使用JavaAPI库访问本机系统功能,并连接到基于Java的中间件应用程序。

JavaFX应用程序的页面可以自定义。CSS将页面外观和样式实现分离,以便开发人员能够集中精力进行编码。前端人员可以通过CSS轻松定制应用程序的外观和样式。如果您有web设计背景,或者希望将用户界面(UI)和后端逻辑分开,则可以使用FXML脚本语言开发UI的表示方面,并使用Java代码作为程序逻辑。如果您喜欢在不编写代码的情况下设计UI,那么可以使用JavaFX场景生成器。在设计UI时,Scene Builder会创建FXML标记,该标记可以移植到集成开发环境(IDE),以便开发人员可以添加业务逻辑。

##可用性

JavaFXAPI作为JavaSE运行时环境(JRE)和Java开发工具包(JDK)的完全集成功能提供。由于JDK可用于所有主要的桌面平台(Windows、Mac OS X和Linux),因此编译为JDK 7和更高版本的JavaFX应用程序也可在所有主要的桌面平台上运行。JavaFX8还提供了对ARM平台的支持。包括JavaFX的基础、图形和控件组件。

跨平台兼容性为JavaFX应用程序开发人员和用户提供了良好的运行时体验。Oracle确保在所有平台上同步发布和更新,并提供广泛的支持计划适用于运行关键任务应用程序的公司。

##主要特征

JavaFX8及更高版本中包含以下功能。JavaFX 8发行版中引入的项目将相应显示:

-Java API。JavaFX是一个Java库,由用Java代码编写的类和接口组成。这些API被设计成Java虚拟机(JavaVM)语言(如JRuby和Scala)的替代品。

-FXML和场景生成器。FXML是一种基于XML的声明性标记语言,用于构建JavaFX应用程序用户界面。设计师可以使用FXML编码或使用JavaFX场景生成器交互设计图形用户界面(GUI)。场景生成器生成FXML标记,该标记可以移植到IDE,开发人员可以在IDE中添加业务逻辑。

-网络视图。一种web组件,它使用WebKitHTML技术使在JavaFX应用程序中嵌入网页成为可能。WebView中运行的JavaScript可以调用JavaAPI,JavaAPI可以调用WebView中运行的JavaScript。JavaFX8中增加了对额外HTML5功能的支持,包括Web套接字、Web工作人员和Web字体,以及打印功能。

-Swing互操作性。现有的Swing应用程序可以使用JavaFX功能进行更新,如富图形媒体播放和嵌入式Web内容。JavaFX8中添加了“SwingNode”类,该类使您能够将Swing内容嵌入JavaFX应用程序。

-内置UI控件和CSS。JavaFX提供了开发全功能应用程序所需的所有主要UI控件。组件可以使用标准Web技术(如CSS)进行设计。DatePicker和TreeTableView UI控件现在在JavaFX8版本中可用。