Welcome!

XML Authors: Liz McMillan, Elizabeth White, Sandi Mappic, Max Katz, Yakov Fain

Related Topics: Java, XML, Linux, Open Source, AJAX & REA, Web 2.0

Java: Blog Feed Post

JavaFX Event Handling and Property Binding

In JavaFX an event object is represented by the instance of the class javafx.event.Event

Some time ago I blogged that Java Swing should be deprecated and replaced with JavaFX. In this blog I’ll show a piece of JavaFX namely event handlers and binding. I’ve created a simple Sign In window with a GridPane layout (it’s JavaFX equivalent of Swing’s GridBagLayout). I’m not going to spend much time on the GridPane itself, but will show you a basic event handling and a binding.

In JavaFX an event object is represented by the instance of the class javafx.event.Event. There are different ways of handling events. Depending on how you structured your application you can handle events either in Java or in FXML. In this blog I’ll do everything in Java, where you can process events using one of the following techniques:

  1. Create an instance of an anonymous class overriding its handle() callback method. Pass it to the the event handler for a specific event.
  2. Use lambda expressions.
  3. Use Java method references introduced in Java 8.

The Sign In window, will have the buttons Sign In, Cancel, and the hyperlink Forgot password. Each of these controls will use different way of handling click event. The Sign In window will look as follows:

f1807

Read the original blog entry...

More Stories By Yakov Fain

Yakov Fain is a co-founder of two software companies: Farata Systems and SuranceBay. He authored several technical books and lots of articles on software development. Yakov is Java Champion (https://java-champions.java.net). He leads leads Princeton Java Users Group. Two of Yakov's books will go in print this year: "Enterprise Web Development" (O'Reilly) and "Java For Kids" (No Starch Press).