O'Reilly logo

Beginning JavaFX™ by Praveen Mohan, Lawrence PremKumar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 11. Triggers

A trigger is a block of code that is attached to a variable and executed whenever the value of the variable changes, including the assignment of the initial value. You can also optionally get hold of the old values that were replaced within the trigger. Triggers are very powerful and unique in JavaFX Script, just like bind. Triggers can be attached to normal variables as well as to sequences. First let us see how triggers work for simple variables and then proceed to complicated triggers and sequence triggers.

Defining a Simple Trigger

Here is the typical syntax of a trigger defined on a variable:

Syntax

var <var name>[:data type] [= <initial value>] on replace [old value] {
           // block of code to be executed on value change
       }

or ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required