This Apress imprint is published by the registered company APress Media, LLC part of Springer Nature.
The registered company address is: 1 New York Plaza, New York, NY 10004, U.S.A.
To my father-in-law Mr. Jim Baker
—Kishori Sharan
To my niece Alina
—Peter Späth
Java had the support for developing GUI applications since its version 1.0 using the AWT (Abstract Window Toolkit). Later, AWT was replaced by Swing, which gave a little better user experience, but still lacked the modern-looking widgets and the support for a developer’s productivity. Both AWT and Swing lacked the first-class support for data binding, efficient GUI rendering engines, easy-to-use 2D and 3D libraries for developers, and style sheet support. JavaFX was first released in 2008 as the tool to use for developing rich Internet applications (RIAs); it used a statically typed declarative language called JavaFX Script, which did not attract a lot of attention from Java developers. JavaFX 2.0, released in 2011, caught the Java community’s attention when it dropped the support for JavaFX Script and supported writing JavaFX programs using the Java programming language. In its current version, JavaFX 17 is supported as an open source add-on that can be downloaded from the Gluon company’s website. Now JavaFX 17 is considered a real successor for Swing for building the GUI application using the Java platform.
Learn JavaFX 17 shows you how to start developing rich client desktop applications in JavaFX 17 using your Java skills. It provides comprehensive coverage of the JavaFX 17 features. Each chapter starts with an introduction to the topic at hand. A step-by-step discussion of the topic with small snippets of code follows. At the end of the topic’s discussion, a complete program is presented. Special care has been taken to present the topics in such a way that chapters can be read serially. The book contains numerous pictures to aid you in visualizing the GUI that is built at every step in the discussion.
The book starts with an introduction to JavaFX and its history. It lists the system requirements and the steps to start developing JavaFX applications. It shows you how to create a Hello World application in JavaFX, explaining every line of code in the process. Later in the book, advanced topics such as 2D and 3D graphics, charts, FXML, advanced controls, and printing are discussed.
I faced a few hurdles while writing the first edition of this book. As JavaFX 8 was being developed, JavaFX 2, the version before JavaFX 8, was the first release of JavaFX that used the Java programming language to write JavaFX code. There were a few bugs in JavaFX 2. Sometimes, it took me a couple of days of hard work to create an example to work with, only to realize that there was a bug in it. Later, if something did not work, I would look at the JIRA bug reports for JavaFX before spending too much time researching it myself. I had to fix bugs as I found them. It took me 18 months to finish this book, and, in the end, it was satisfying to see that what I had produced was a lot of useful material covering almost every topic in JavaFX so fully that readers could use it to learn and build a rich client application quickly using JavaFX. I hope you will enjoy the book and benefit greatly from it.
I believe that programming is simple if you learn it that way. Keeping this in mind, I kept the examples in the book as simple as possible, presenting them in as few lines as I could. The examples focus on the topic being discussed. I do not present complex GUI in my examples, keeping in mind that this could obscure the learning process of the topic at hand. I have seen books that contain examples that run four or five pages long, sometimes even longer; readers of such books (myself included) often get lost in trying to understand the logic of the program, thus forgetting what they were trying to learn in that section. Therefore, simple programs in this book are intended to help you learn JavaFX faster. The book includes many ready-to-run programs and even more pictures. Having more pictures than programs is evident from my approach in keeping the readers’ interest the first priority. Almost every time I discuss a snippet of code producing a UI, I include the picture of the results of the UI, so readers are not left to their imaginations as to what the code snippet will produce. Having to run every snippet of code to see the output can hinder the learning rhythm.
The book contains 27 chapters covering all topics—from basic to advanced—in JavaFX. Chapters are arranged in an order that aids you to quickly learn JavaFX. I have used an incremental approach to teach JavaFX, assuming no prior GUI development knowledge. Each chapter starts with a section introducing the topic to be discussed in the chapter. Each section contains a bit of background of the features being discussed, followed with code snippets and a complete program.
What JavaFX 17 is and its history
How to develop rich client desktop applications using JavaFX 17
How to use properties, collections, colors, and styles
How to use controls and handle events to build modern GUI applications
How to use advanced controls such as TreeView, TableView, and TreeTableView
How to access web pages in JavaFX applications
How to draw 2D and 3D shapes and apply effects and transformations
How to create animations and charts using the JavaFX 17 APIs
How to add audios and videos to your applications
How to create GUIs in JavaFX using FXML
How to provide the printing capabilities using the JavaFX Print API
Learn JavaFX 17 was written for Java developers, with beginning to intermediate-level Java skills, who want to learn how to develop modern desktop GUI applications using JavaFX 17.
Source code for this book can be accessed at github.com/apress/learn-javafx17.
My heartfelt thanks are due to my father-in-law, Jim Baker, for displaying extraordinary patience in reading the initial draft of the first few chapters of the book and his valuable suggestions for improving the material.
I thank my friend Richard Castillo for his hard work in reading the initial draft of the first 12 chapters of the book and weeding out several mistakes. Richard was instrumental in running all examples and pointing out errors. I also thank him for allowing me to use a few pictures in this book from his website www.digitizedchaos.com.
My wife, Ellen, was always patient when I spent long hours at my computer desk working on this book. I thank her for all her support to me in writing this book. She also deserves my sincere thanks for letting me sometimes seclude myself on weekends so I could focus on this book.
I also thank my family members and friends for their encouragement and support to me in writing this book: my elder brothers, Janki Sharan and Dr. Sita Sharan; my sister and brother-in-law, Ratna and Abhay; my nephews Babalu, Dabalu, Gaurav, Saurav, and Chitranjan; my friends Shivashankar Ravindranath, Kannan Somasekar, Mahbub Choudhury, Biju Nair, Srinivas Kakkera, Anil Kumar Singh, Chris Coley, Willie Baptiste, Rahul Jain, Larry Brewster, Greg Langham, LaTondra Okeke, Dinesh Sankala, Rahul Nagpal, Ravi Datla, and many more friends not mentioned here.
I thank the president of my company Up and Running Inc., Josh Bush, for his support and my wonderful, supportive coworkers—Preethi Vasudeva, Tanina Jones, Ann Wedgeworth, William Barnett, and Shannah Glenn—for their encouragement.
My sincere thanks are due to the wonderful team at Apress for their support during the publication of this book. Thanks to Mark Powers, the senior coordinating editor, and Matthew Moodie, the development editor, for providing excellent support. Thanks also to the technical reviewers Jeff Friesen, David Coffin, Wallace Jackson, Massimo Nardone, and Tri Phan for their insights and feedback during the editing process; they were instrumental in weeding out many technical errors and improving the material. I also thank the copy editors, Mary Bearden, Lori Cavanaugh, Lori Jacobs, and Karen Jameson, for their extraordinary efforts in editing the book and applying many corrections during a very short span of time. Last but not least, my sincere thanks to Steve Anglin, the lead editor at Apress, for taking the initiative for the publication of this book.
—Kishori Sharan
Many thanks to the Apress staff for offering me to write the JavaFX version 17 edition of this book. Thanks also to my friends for their patience concerning updates to my latest composition work, a classic style Tango for violin and cello. This work had to stand behind a little bit, so the JavaFX book’s schedule could be held.
—Peter Späth
graduated in 2002 as a physicist and soon afterward became an IT consultant, mainly for Java-related projects. In 2016, he decided to concentrate on writing books on various aspects, but with a main focus on software development. With two books about graphics and sound processing, three books on Android app development, and several books on Java development, the author continues his effort in writing software development–related literature.
earned an MS in Computer Information Systems and Cyber Security from Auburn University, Alabama. She is an Oracle-certified Java 8 programmer with more than 15 years of industry experience in investment banking, healthcare, and other areas. She is interested in Java and related technologies and enjoys participating in coding competitions.