Custome DoubleBinding by subclassing : DoubleBinding « JavaFX « Java






Custome DoubleBinding by subclassing

 
import javafx.beans.binding.DoubleBinding;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;

public class Main {
  public static void main(String[] args) {
    final DoubleProperty radius = new SimpleDoubleProperty(2);

    DoubleBinding volumeOfSphere = new DoubleBinding() {
        {
            super.bind(radius);
        }

        @Override
        protected double computeValue() {
            return radius.get()+4;
        }
    };

    System.out.println(radius.get());
    System.out.println(volumeOfSphere.get());
    
    radius.set(50);
    System.out.println(radius.get());
    System.out.println(volumeOfSphere.get());
  }
}

   
  








Related examples in the same category

1.Override computeValue from DoubleBinding
2.Subclass DoubleBinding with custom computeValue method