Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Mastering JavaFX 10
Mastering JavaFX 10

Mastering JavaFX 10: Build advanced and visually stunning Java applications

eBook
AU$36.99 AU$53.99
Paperback
AU$67.99
Subscription
Free Trial
Renews at AU$24.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Table of content icon View table of contents Preview book icon Preview Book

Mastering JavaFX 10

Building Blocks – Shapes, Text, and Controls

To construct a rich user interface, you need the building blocks. JavaFX provides a large range of very customizable graphical instruments. We'll start from the smallest building blocks—shapes, text, and simple controls—and will use them to understand how JavaFX works with graphical elements.

In this chapter, we will cover the following topics

  • Creating and customizing the shapes
  • Working with text
  • Coordinates and bounds
  • Basic controls

By combining and customizing these Nodes and arranging them using the layout managers we reviewed in the previous chapter, you can already build a sophisticated UI. At the end of the chapter, we'll revisit the Clock application from the previous chapter to demonstrate the topics we learned in a more complex application.

Shapes and their properties

Everything you see on the screen of your computer can be split into three large categories:

  • Shapes
  • Text
  • Images

Thus, by being able to create each of these, you can build any UI in reasonable time. Let's start with JavaFX shapes.

JavaFX shapes overview

The simplest object you can put on a scene is a shape. Under the javafx.scene.shape package, the JavaFX API supports a great range of shapes, from circles and rectangles to polygons and SVG paths. Most shapes can be divided then into two categories—lines and closed shapes. The properties that are shared among all shapes will be covered in the next section. After, we will review each shape's specific APIs.

...

Transformations

JavaFX API supports basic transformations for every Node (and Shape, which extends Node).

Three basic transformations can be used through Node methods:

  • setRotate (double angle): Rotates around the center of the Node
  • setTranslateX (double pixels), setTranslateY (double pixels): Shifts the Node by a set amount of pixels
  • setScaleX (double scale), setScaleY (double scale): Increases (or decreases) the Node by multiplying its horizontal or vertical dimensions by scale

For more complex transformations, the Transform class can be used. It allows us to work precisely with every parameter of the transformation. For example, you can concatenate two transformations into one combined and use two different nodes to save.

Note that through Transform, there are usually more options available. For example, the setRotate() method always uses the center of the shape as a pivot...

Coordinates and bounds

Let's look into determining Shape and Node bounds in Scene and Scenegraph.

The simplest of all are layoutBounds. These rectangular bounds are used for all size and location calculations for this Node, and describe its basic shape size. They don't include any extra effects or transformations.

The next thing is boundsInLocal. These bounds include all information about effects. So, you can determine how large of an area is covered by your Node or Shape.

The last one is boundsInParent. These are bounds after all transformations as well and bounding rectangles uses their parents' coordinate system.

Working with Bounds Demo

There is a very nice public demo by Kishori Sharan that shows how bounds...

Basic Controls

Controls are a special subset of Node objects that were designed to handle user interaction. Most of them allow user input and support focus traversal.

Another difference from Shape is that Control objects are inherited not directly from Node but through the Region interface (like layout managers), which means their size and location are not fixed and can be managed by layout managers.

Button and Event Handlers

The first and most common control is button's family. Button has an EventHandler that is called when Button is clicked (or fired). All code in the event handler is always run on JavaFX Application Thread:

// chapter2/other/ButtonDemo.java
Button btn = new Button();
btn.setText("Say 'Hello...

Clock demo

Let's apply some of the stuff we learned in this Chapter to the Clock demo we started in the previous chapter.

The digital clock is not as fun as an analog one, so let's add hands to it.

We need three hands—hours, minutes, and seconds. We'll use a simple line for the seconds hand and slightly more complex path shapes for the hour and minute ones. For example, here is the path for the minute hand:

Path minuteHand = new Path(
new MoveTo(0, 0),
new LineTo(15, -5),
new LineTo(100,0),
new LineTo(15,5),
new ClosePath());
minuteHand.setFill(Color.DARKGRAY);

This code gives us not the prettiest but a conveniently simple hand. We'll work on making it nicer in following chapters:

To show time, the hand has to rotate. We'll use the Rotate transformation. We need to rotate...

Summary

In this chapter, we've studied a lot of different building blocks for JavaFX applications: shapes, text, and simple controls. Also, we looked at various ways to customize them. With these tools, you can already build a visually rich JavaFX UI.

The only problem is that it will be static, which is not enough for a modern application. In the next two chapters, we will learn about Binding and Animation, which will allow us to develop more dynamic applications.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Leverage advanced GUI programming techniques using the latest JavaFX 10 framework.
  • Create dynamic content using the animation API and work with different application layers
  • Create and customize plugins and use them efficiently in different applications

Description

: 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.

Who is this book for?

If you’re a Java developer who wants to upgrade to the latest version of JavaFX to create stunning, feature-rich graphical applications, this book is for you. Some basic knowledge of Java programming is necessary to get the most out of this book. prior JavaFX knowledge will help but is not mandatory.

What you will learn

  • •Construct and customize JavaFX windows
  • •Manage UI elements and arrange them on the Scene
  • •Explore the Bindings API and use it to coordinate various UI elements
  • •Use FXML to design amazing FX applications
  • •Write and manage CSS to style your applications
  • •Add audio and video to your projects
  • •Prepare your application to be launched on the target platform

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : May 31, 2018
Length: 268 pages
Edition : 1st
Language : English
ISBN-13 : 9781788299022
Vendor :
Oracle
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want

Product Details

Publication date : May 31, 2018
Length: 268 pages
Edition : 1st
Language : English
ISBN-13 : 9781788299022
Vendor :
Oracle
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
AU$24.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
AU$249.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just AU$5 each
Feature tick icon Exclusive print discounts
AU$349.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just AU$5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total AU$ 325.97
Learning JavaFX by Example (v)
AU$189.99
Design Patterns and Best Practices in Java
AU$67.99
Mastering JavaFX 10
AU$67.99
Total AU$ 325.97 Stars icon

Table of Contents

14 Chapters
Stages, Scenes, and Layout Chevron down icon Chevron up icon
Building Blocks – Shapes, Text, and Controls Chevron down icon Chevron up icon
Connecting Pieces – Binding Chevron down icon Chevron up icon
FXML Chevron down icon Chevron up icon
Animation Chevron down icon Chevron up icon
Styling Applications with CSS Chevron down icon Chevron up icon
Building a Dynamic UI Chevron down icon Chevron up icon
Effects Chevron down icon Chevron up icon
Media and WebView Chevron down icon Chevron up icon
Advanced Controls and Charts Chevron down icon Chevron up icon
Packaging with Java9 Jigsaw Chevron down icon Chevron up icon
3D at a Glance Chevron down icon Chevron up icon
What's Next? Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8
(9 Ratings)
5 star 55.6%
4 star 11.1%
3 star 11.1%
2 star 0%
1 star 22.2%
Filter icon Filter
Top Reviews

Filter reviews by




Guenther Bachmann Dec 13, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Sehr gutes Buch für Anfänger und Fortgeschrittene
Feefo Verified review Feefo
Gevaert Jan 11, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Enfin un livre clair et didactique sur javaFXIndispensable !
Amazon Verified review Amazon
Mikhail Vaysman Sep 24, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book does an excellent job to explain each aspect of JavaFX for the absolute beginner (as I'm). The book contains many examples that are hosted on GitHub (it is very convenient).Since this book is about GUI, I ignored other parts of the examples (like deprecated methods, warnings, etc.). I wanted to learn how to create a GUI in JavaFX, and this book will help me get started.I definitely will use this book as a reference manual when I need to create a GUI in Java.
Amazon Verified review Amazon
Sherwin John C. Tragura Mar 12, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
All JavaFx literatures i read before are not that organized, concrete, and comprehensive as this book. Great book! This helped me with my training lectures.
Amazon Verified review Amazon
Alla Redko Sep 26, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Mastering JavaFX 10 is a perfect collection of smart, real-life, and visually appealing tutorials. Anyone who wants to learn JavaFX 10 from the very beginning can easily find the required directions and guidelines. On the other hand, those, who already use previous versions of JavaFX, can benefit from new insights and advanced examples.My personal experience with JavaFX is limited to the JavaFX 8 release. Sergey's book helped me quickly grasp the new features appeared in the latest releases of JavaFX. In particular, I found the Packaging with Java 9 Jigsaw chapter very helpful as it covers the concepts I wasn't fully aware of. Also, I couldn't imagine how 3D effects can be straightforward and easy to apply. I highly recommend this book to all GUI developers.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.