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

Arrow left icon
Profile Icon Sergey Grinev
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8 (9 Ratings)
Paperback May 2018 268 pages 1st Edition
eBook
$27.98 $39.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Sergey Grinev
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8 (9 Ratings)
Paperback May 2018 268 pages 1st Edition
eBook
$27.98 $39.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$27.98 $39.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781788293822
Vendor :
Oracle
Category :
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.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
$199.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 $5 each
Feature tick icon Exclusive print discounts
$279.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 $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 235.97
Learning JavaFX by Example (v)
$137.99
Design Patterns and Best Practices in Java
$48.99
Mastering JavaFX 10
$48.99
Total $ 235.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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.