Code and a handout for a JavaFX workshop
Shippable status:
Travis status:
The workshop is an internal event for my coworkers. Target audience are developers who haven't heard much about JavaFX and want to know basic concepts and be able to build modern user interfaces.
The code works with Java 7 and Java 8.
Part of this workshop is inspired by Hendrik Ebbers book "Mastering JavaFX Controls" and from his repository at https://github.com/guigarage/mastering-javafx-controls.
To get a good start in the workshop, I line out the first chapter ("Building your first FX application") in more detail. Read the following and have a look at the code. Then you are ready to go for the more advanced topics.
Part 1: SceneBuilder and .fxml-files
The entry point for JavaFX applications is the Application class. The JavaFX runtime does the following, in order, whenever an application is launched:
Constructs an instance of the specified Application class
Calls the init() method
Calls the start(javafx.stage.Stage) method
Waits for the application to finish, which happens when either of the following occur:
the application calls Platform.exit() OR the last window has been closed and the implicitExit attribute on Platform is true
- Calls the stop() method
This is our first UI:
Part 2: Properties and binding
Properties are a language extension - expect them to come around in the backend, too.
extension of bean naming convention:
setMyFoo(...) {...}
getMyFoo() {...}
myFooProperty() {...}
There is unidirectional and bidirectional binding:
myProperty.bind(...);
myProperty.bindBidirectional(...);
you can do math with properties, for example: sum.bind(amountOfApples.add(amountOfChips).add(amountOfPotatoes));
you can listen on properties and get notified if there's a change
great article about difference between ChangeListener and InvalidationListener: http://blog.netopyr.com/2012/02/08/when-to-use-a-changelistener-or-an-invalidationlistener/ (in short: InvalidationListener doesn't give you old and new value and fires even without the data changing. ChangeListener however is less performant.
With properties, we can calculate the sum of the items in our list:
Part 3: Charts - the pie chart
A chart makes our shopping list much more interesting:
Part 4: Styling with CSS
either directly for one component in SceneBuilder or in the code or in a CSS (you want to have the latter!)
behold: not all CSS tags are available in JavaFX and you have to add a "-fx" before them:
-fx-background-color:red
just in JavaFX - CSS: dropshadow
With styling, we now have a realy nice looking shopping list:
All files in this repository are under Creative Commons 4.0 (see http://creativecommons.org/licenses/by/4.0/).
You are free to:
The licensor cannot revoke these freedoms as long as you follow the license terms.
Under the following terms: