Book Image

Mastering JavaFX 10

By : Sergey Grinev
5 (1)
Book Image

Mastering JavaFX 10

5 (1)
By: Sergey Grinev

Overview of this book

: JavaFX 10 is used to create media-rich client applications. This book takes you on a journey to use JavaFX 10 to build applications that display information in a high-performance, modern user interface featuring audio, video, graphics, and animation. Mastering JavaFX 10 begins by introducing you to the JavaFX API. You will understand the steps involved in setting up your development environment and build the necessary dependencies. This is followed by exploring how to work with the assets, modules, and APIs of JavaFX. This book is filled with practical examples to guide you through the major features of JavaFX 10. In addition to this, you will acquire a practical understanding of JavaFX custom animations, merging different application layers smoothly, and creating a user-friendly GUI with ease. By the end of the book, you will be able to create a complete, feature-rich Java graphical application using JavaFX.
Table of Contents (15 chapters)

Loading CSS files from the JavaFX code

Let's look more thoroughly at the options we have to select a CSS file to load.

The first way is to use the full folder path to the file:

scene.getStylesheets().add("/chapter6/basics/style.css");

This approach works reliably only if you store your CSS files in a separate resource folder. If your CSS lies along the Java code, any refactoring of the packages may miss this String constant. In this case, the better option will be to use a relative path:

scene.getStylesheets().add(getClass().getResource("style.css").toExternalForm());

By this call, we tell JavaFX to look for style.css in the same folder as a current class file.

And the last option is to not store CSS within your project at all but load it from the web:

scene.getStylesheets().add("https://raw.githubusercontent.com/sgrinev/mastering-javafx-9-10-book...