首页 JFXMG-Mastering FXML

JFXMG-Mastering FXML

举报
开通vip

JFXMG-Mastering FXML JavaFX Mastering FXML Release 8 E50650-01 March 2014 In this tutorial, you learn the reasons you should use FXML, get information about the FXML enhancements made in JavaFX releases 2.1 and 2.2; create the sample Address Book application using FXML...

JFXMG-Mastering FXML
JavaFX Mastering FXML Release 8 E50650-01 March 2014 In this tutorial, you learn the reasons you should use FXML, get information about the FXML enhancements made in JavaFX releases 2.1 and 2.2; create the sample Address Book application using FXML and a sample application with a custom control; and get information about why some FXML applications need digital signatures. JavaFX Mastering FXML, Release 8 E50650-01 Copyright © 2011, 2014, Oracle and/or its affiliates. All rights reserved. Primary Author: Irina Fedortsova Contributor: Greg Brown This software and related documentation are provided under a license agreement containing restrictions on use and disclosure and are protected by intellectual property laws. Except as expressly permitted in your license agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify, license, transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means. Reverse engineering, disassembly, or decompilation of this software, unless required by law for interoperability, is prohibited. The information contained herein is subject to change without notice and is not warranted to be error-free. If you find any errors, please report them to us in writing. If this is software or related documentation that is delivered to the U.S. Government or anyone licensing it on behalf of the U.S. Government, the following notice is applicable: U.S. GOVERNMENT END USERS: Oracle programs, including any operating system, integrated software, any programs installed on the hardware, and/or documentation, delivered to U.S. Government end users are "commercial computer software" pursuant to the applicable Federal Acquisition Regulation and agency-specific supplemental regulations. As such, use, duplication, disclosure, modification, and adaptation of the programs, including any operating system, integrated software, any programs installed on the hardware, and/or documentation, shall be subject to license terms and license restrictions applicable to the programs. No other rights are granted to the U.S. Government. This software or hardware is developed for general use in a variety of information management applications. It is not developed or intended for use in any inherently dangerous applications, including applications that may create a risk of personal injury. If you use this software or hardware in dangerous applications, then you shall be responsible to take all appropriate failsafe, backup, redundancy, and other measures to ensure its safe use. Oracle Corporation and its affiliates disclaim any liability for any damages caused by use of this software or hardware in dangerous applications. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners. Intel and Intel Xeon are trademarks or registered trademarks of Intel Corporation. All SPARC trademarks are used under license and are trademarks or registered trademarks of SPARC International, Inc. AMD, Opteron, the AMD logo, and the AMD Opteron logo are trademarks or registered trademarks of Advanced Micro Devices. UNIX is a registered trademark of The Open Group. This software or hardware and documentation may provide access to or information on content, products, and services from third parties. Oracle Corporation and its affiliates are not responsible for and expressly disclaim all warranties of any kind with respect to third-party content, products, and services. Oracle Corporation and its affiliates will not be responsible for any loss, costs, or damages incurred due to your access to or use of third-party content, products, or services. iii Contents Preface ................................................................................................................................................................. v About This Tutorial..................................................................................................................................... v Audience....................................................................................................................................................... v Documentation Accessibility ..................................................................................................................... vi Related Documents ..................................................................................................................................... vi Conventions ................................................................................................................................................. vi 1 Why Use FXML Introduction to FXML ................................................................................................................................ 1-1 Simple Example of FXML ......................................................................................................................... 1-2 Benefits of FXML........................................................................................................................................ 1-2 FXML and Scene Builder .......................................................................................................................... 1-3 2 FXML Enhancements in JavaFX Releases 2.1 and 2.2 FXML Enhancements Made in JavaFX 2.1 and 2.2 ............................................................................... 2-1 FXML Loader Incompatibilities with Previous JavaFX Releases ..................................................... 2-3 Some JavaFX 2.0 FXML Escape Sequences Are Deprecated in JavaFX 2.1 ..................................2-4 Backslash Is Now an Escape Character .............................................................................................2-4 3 Creating an Address Book with FXML Set Up the Project ....................................................................................................................................... 3-2 Create the Basic User Interface ................................................................................................................ 3-2 Add Columns to the Table ........................................................................................................................ 3-4 Define the Data Model.............................................................................................................................. 3-5 Associate Data with the Table Columns ................................................................................................ 3-6 Set Sort Order on Startup ......................................................................................................................... 3-8 Define Column Widths ............................................................................................................................. 3-8 Set Alignment in Table Cells ................................................................................................................... 3-9 Add Rows to the Table ........................................................................................................................... 3-12 Where to Go from Here .......................................................................................................................... 3-13 4 Creating a Custom Control with FXML Set Up a Project ........................................................................................................................................... 4-1 Create the Basic User Interface ................................................................................................................ 4-2 iv Create a Controller ..................................................................................................................................... 4-2 Load the FXML Source File and Define Stage and Scene .................................................................. 4-3 A FXMLTableView Code FXMLTableView.java ................................................................................................................................ A-1 B fxml_tableview FXML Code fxml_tableview.fxml ................................................................................................................................. B-1 C FXMLTableviewController Code FXMLTableviewController.java.............................................................................................................. C-1 D Person Code Person.java .................................................................................................................................................. D-1 E FormattedTableCellFactory Code FormattedTableCellFactory.java ............................................................................................................. E-1 v Preface This preface describes the document accessibility features and conventions used in this tutorial - Mastering FXML. About This Tutorial This document consists of the following pages: ■ Why Use FXML A basic description of FXML and the benefits of using it to create user interfaces. ■ FXML Enhancements in JavaFX Releases 2.1 and 2.2 A list of FXML enhancements that were introduced in JavaFX releases 2.1 and 2.2. Incompatibilities with previous releases are also discussed. ■ Creating an Address Book with FXML A tutorial that shows how to populate a table with data, sort the data at application startup, align the data in the table cells, and add rows to the table. ■ Creating a Custom Control with FXML A tutorial that shows how to create a custom control using APIs introduced in JavaFX 2.2. You can also get information on FXML from the following resources: ■ Creating a User Interface with FXML A beginning tutorial that shows how to create a login application using FXML. ■ Introduction to FXML A reference document that provides information on the elements that make up the FXML language. The document is included in the javafx.fxml package in the API documentation. ■ JavaFX 2 Forum A place where you can post questions about FXML. Audience This document is intended for JavaFX developers. vi Documentation Accessibility For information about Oracle's commitment to accessibility, visit the Oracle Accessibility Program website at http://www.oracle.com/pls/topic/lookup?ctx=acc&id=docacc. Access to Oracle Support Oracle customers have access to electronic support through My Oracle Support. For information, visit http://www.oracle.com/pls/topic/lookup?ctx=acc&id=info or visit http://www.oracle.com/pls/topic/lookup?ctx=acc&id=trs if you are hearing impaired. Related Documents For more information, see the following documents in the JavaFX documentation set: ■ What Is JavaFX? ■ Getting Started with JavaFX ■ Getting Started with JavaFX Scene Builder Conventions The following text conventions are used in this document: Convention Meaning boldface Boldface type indicates graphical user interface elements associated with an action, or terms defined in text or the glossary. italic Italic type indicates book titles, emphasis, or placeholder variables for which you supply particular values. monospace Monospace type indicates commands within a paragraph, URLs, code in examples, text that appears on the screen, or text that you enter. 1 Why Use FXML 1-1 1Why Use FXML This chapter provides a basic description of FXML and the benefits of using it to create user interfaces. FXML is an XML-based language that provides the structure for building a user interface separate from the application logic of your code. This separation of the presentation and application logic is attractive to web developers because they can assemble a user interface that leverages Java components without mastering the code for fetching and filling in the data. The following sections provide more information about FXML, and when you would choose FXML over other methods of creating a user interface: ■ Introduction to FXML ■ Simple Example of FXML ■ Benefits of FXML ■ FXML and Scene Builder Introduction to FXML FXML does not have a schema, but it does have a basic predefined structure. What you can express in FXML, and how it applies to constructing a scene graph, depends on the API of the objects you are constructing. Because FXML maps directly to Java, you can use the API documentation to understand what elements and attributes are allowed. In general, most JavaFX classes can be used as elements, and most Bean properties can be used as attributes. From a Model View Controller (MVC) perspective, the FXML file that contains the description of the user interface is the view. The controller is a Java class, optionally implementing the Initializable class, which is declared as the controller for the FXML file. The model consists of domain objects, defined on the Java side, that you connect to the view through the controller. An example of this structure is in the tutorial Creating an Address Book with FXML. While you can use FXML to create any user interface, FXML is particularly useful for user interfaces that have large, complex scene graphs, forms, data entry, or complex animation. FXML is also well-suited for defining static layouts such as forms, controls, and tables. In addition, you can use FXML to construct dynamic layouts by including scripts. Simple Example of FXML 1-2 JavaFX Mastering FXML Simple Example of FXML The easiest way to show the advantages of FXML is with an example. Take a look at Figure 1–1, which shows a user interface that includes a border pane layout that has a top and center region, each of which contains a label. Figure 1–1 Border Pane Simple Example First, look at how the user interface is constructed and built directly in the source code, as shown in Example 1–1. Example 1–1 Java Code for a User Interface BorderPane border = new BorderPane(); Label toppanetext = new Label("Page Title"); border.setTop(toppanetext); Label centerpanetext = new Label ("Some data here"); border.setCenter(centerpanetext); Next, look at Example 1–2, which shows the same user interface, but in FXML markup. You can see the hierarchical structure of the user interface, which in turn makes it easier to add components and build upon the user interface. Example 1–2 FXML Markup for a User Interface
Benefits of FXML In addition to providing web developers a familiar approach to designing user interfaces, FXML offers these benefits: ■ Because the scene graph is more transparent in FXML, it is easy for a development team to create and maintain a testable user interface. ■ FXML is not a compiled language; you do not need to recompile the code to see the changes. FXML and Scene Builder Why Use FXML 1-3 ■ The content of an FXML file can be localized as the file is read. For example, if an FXML file is loaded using the en_US locale, then it produces the string "First Name" for a label based on the following resource string:
本文档为【JFXMG-Mastering FXML】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_177790
暂无简介~
格式:pdf
大小:390KB
软件:PDF阅读器
页数:46
分类:互联网
上传时间:2014-03-26
浏览量:4