JavaFX from a Developer’s Point of View
My background is in a lot of Swing development and web application creation. For web applications, I mostly used plain HTML or JSF to create the views, and I did some little applications with most of the other technologies (Adobe Flex, Flash, Android, Wicket, GWT, and so on) to learn more about these UI toolkits over the years.
For me, JavaFX is a perfect combination of most of the best practices that have come out of these technologies. For a Swing developer, most of the basic JavaFX APIs are easy to learn because the main concepts seem to be similar when looking at the framework. Under the hood, most of the technologies are different, but you can structure an application in a better way by using FXML and CSS, for example. Compared to HTML applications, JavaFX development is much easier for me because theoretically, you can do whatever you want and don’t need to think about cross-browser behavior and all that stuff. You can create the complete view by using What You See Is What You Get (WYSIWYG) editors like Scene Builder and use your favorite Java IDE for development.
JavaFX offers a small learning curve, so you’ll be able to create your first applications quickly. In addition, because of the good documentation and structure of the APIs, you probably won’t make as many mistakes as you might have when learning Swing or HTML, for example. But, there are some places where you need to know the underlying technology well, and some parts are hard when you experiment the first time with them. When creating my first custom JavaFX control, I needed a lot of help to understand all the concepts and APIs involved. That was before JavaFX 8, though, and most of the documentation that is available today didn’t exist. For me, as a Java developer, JavaFX is the best choice to develop applications that don’t need to be captured in a browser.
With the release of Java 8, JavaFX is the default UI toolkit for Java. In this book, you will learn how to master JavaFX, especially the control API, to create applications based on these technologies. You can get all the scripts and programs featured in this book online (see the section “Retrieving the Examples” for details).
With this book, you will perform the following tasks:
Create a structure for JavaFX applications
Understand the general APIs of JavaFX
Define layouts for all the views of an application
Use the JavaFX bindings and property APIs to bind controls and a custom data model
Understand the basic APIs and technologies of the scene graph
Explore all the basic control types that are part of JavaFX
Use FXML to separate the view layer
Style specific controls or a complete application by using CSS
Create custom controls the right way
This book contains 10 chapters and one appendix.
Chapter 1: The History of Java UI Toolkits This chapter gives a short overview of Java UI toolkits and how UI toolkits and their features have evolved over the past few years.
Chapter 2: JavaFX Basics In this chapter, you will find short descriptions of the JavaFX core APIs and useful tools.
Chapter 3: The Scene Graph This chapter covers the core concepts of the scene graph and the associated APIs.
Chapter 4: Laying Out and Transforming Nodes in the Scene Graph This chapter starts with an overview of the transformation types that can be used in JavaFX. The second part describes the layout algorithms of JavaFX and how to define custom layouts.
Chapter 5: JavaFX Basic Controls After describing the core concepts of the Control
class, this chapter gives an overview of all the basic control types that are part of JavaFX and shows how to use the controls and their features.
Chapter 6: Additional JavaFX Controls This chapter discusses more complex controls such as the TableView
and DatePicker
. The chapter ends with an interview with Jonathan Giles.
Chapter 7: Additional JavaFX Nodes In addition to the already described controls, JavaFX contains some useful node types such as charts and the WebView. This chapter covers these special node types.
Chapter 8: Integrating JavaFX, Swing, and SWT This chapter covers some best-practice workflows for integrating JavaFX in Swing or SWT. This can be useful when migrating a Swing or SWT application to JavaFX.
Chapter 9: Styling a Control This chapter describes the CSS support of JavaFX. After a short general introduction of CSS, this chapter covers different use cases for styling controls and applications in JavaFX. In addition, the chapter concludes with an interview with Claudine Zillmann.
Chapter 10: Custom Controls This chapter shows how you can create custom JavaFX controls. In a hands-on example, you’ll use all the APIs and techniques discussed in the earlier chapters. The chapter ends with an interview with Gerrit Grunwald.
Appendix: JavaFX Resources and Where to Go from Here The appendix gives you a general overview of other useful resources for JavaFX.
Intended Audience
This book is suitable for the following readers:
Developers who need to write JavaFX applications
Developers who want to know more about the differences between Swing and JavaFX
Developers who want to create a desktop application and are searching for the right technologies
Retrieving the Examples
I hope you enjoy this book and JavaFX!
Acknowledgments
When writing this book, I stumbled over some topics where I couldn’t offer enough expert knowledge to provide the solutions and descriptions in the right way. Thanks to the JavaFX community, a lot of experts helped me out, and I want to thank each of them:
Jonathan Giles: I had a lot of questions about specific APIs, and you always had the perfect answer.
Simon Ritter: You did a great review of the whole book and often moved the topics in the right direction.
Claudine Zillmann: You are my CSS guru.
Gerrit Grunwald: You were the perfect person to discuss the general structure of the topics.
Thank you also to Johan Vos for many productive discussions, Tom Schindl for showing me how to combine JavaFX and SWT, Arnd Kleinbeck and Simon Skoczylas for reviewing some of my chapters, and Alexander Casall, Mark Heckler, Dierk König, and Carl Dea for your contribution of several cool tips and tricks.
In addition, I want to thank Amanda Russell and Brandi Shailer at McGraw-Hill Professional. You both managed the whole development process of this book, reviewed my chapters, and always offered useful tips and tricks.