JavaFX ReadOnlyDoubleProperty nan Or Infinity - Java JavaFX

Java examples for JavaFX:Bindable Properties

Description

JavaFX ReadOnlyDoubleProperty nan Or Infinity

Demo Code


//package com.java2s;

import javafx.beans.binding.DoubleBinding;

import javafx.beans.property.*;

public class Main {
    public static ReadOnlyDoubleProperty nanOrInfinity(
            final ReadOnlyDoubleProperty property) {
        DoubleProperty result = new SimpleDoubleProperty();

        result.bind(new DoubleBinding() {
            {/*  w  w  w  .ja  va  2 s .  com*/
                super.bind(property);
            }

            @Override
            protected double computeValue() {
                double value = property.get();

                if (Double.isInfinite(value) || Double.isNaN(value)) {
                    return 0;
                } else {
                    return property.get();
                }
            }
        });

        return result;
    }
}

Related Tutorials