Java Reference
In-Depth Information
public var minimum:Integer = getMinimum() on replace {
getModel().setMinimum(minimum);
};
The maximum variable is handled in a similar way with the getMaximum() returning
java.lang.Integer.MAX_VALUE if the SpinnerNumberModel maximum property
is null.
Now, all the JavaFX instance variables are connected to the JavaBean properties,
but only in one direction. Whenever the JavaFX instance variable changes, the
corresponding property in the JavaBean class will also be updated. For example,
if the JavaFX variable, value , is set to 50, the SpinnerNumberModel value
property will also be set to 50 and the JSpinner 's view will accordingly be
updated to show 50. To finish the connection, though, we need to know when the
JSpinner changes its properties. These kinds of changes can originate from the
user typing in a number in the JSpinner 's entry box or using the up or down but-
tons to sequence through the numbers.
To connect changes originating from the JavaBean, we need to install event lis-
teners on the JavaBean object. The type of event listener to install varies depend-
ing on what the JavaBean object supports. Many of the Java GUI classes support
the java.beans.PropertyChangeListener interface to notify other objects of
change to one of its properties. However, in this example, we are more interested
in the properties contained in the SpinnerNumberModel object that is installed in
the JSpinner component. JSpinner supports the javax.swing.event.Change-
Listener interface that handles ChangeEvents . Change events are fired when
the source object wants to notify interested listeners that some state has changed
within the object. We need to register a ChangeListener on the JSpinner object
so that our JavaFX object is notified that the JSpinner has changed its state.
To do this, we need to add code to the init block for the JavaFX SwingNumber-
Spinner class.
init {
var sp = getJSpinner();
sp.addChangeListener( ChangeListener {
override function stateChanged(e:ChangeEvent)
: Void {
if(not inChange) {
value = getModel().getNumber().
intValue();
minimum = getMinimum();
maximum = getMaximum();
stepSize = getModel().getStepSize().
intValue();
Search WWH ::




Custom Search