Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering JavaFX 10

You're reading from   Mastering JavaFX 10 Build advanced and visually stunning Java applications

Arrow left icon
Product type Paperback
Published in May 2018
Publisher Packt
ISBN-13 9781788293822
Length 268 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Sergey Grinev Sergey Grinev
Author Profile Icon Sergey Grinev
Sergey Grinev
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Stages, Scenes, and Layout FREE CHAPTER 2. Building Blocks – Shapes, Text, and Controls 3. Connecting Pieces – Binding 4. FXML 5. Animation 6. Styling Applications with CSS 7. Building a Dynamic UI 8. Effects 9. Media and WebView 10. Advanced Controls and Charts 11. Packaging with Java9 Jigsaw 12. 3D at a Glance 13. What's Next? 14. Other Books You May Enjoy

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...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image