खोज…


साधारण संपत्ति बंधन

JavaFX में एक बाइंडिंग एपीआई है, जो एक प्रॉपर्टी को दूसरे को बाइंड करने के तरीके प्रदान करता है। इसका मतलब है कि जब भी किसी संपत्ति का मूल्य बदला जाता है, तो बाध्य संपत्ति का मूल्य स्वचालित रूप से अपडेट किया जाता है। सरल बंधन का एक उदाहरण:

SimpleIntegerProperty first =new SimpleIntegerProperty(5); //create a property with value=5
SimpleIntegerProperty second=new SimpleIntegerProperty();

public void test()
{
    System.out.println(second.get()); // '0'
    second.bind(first);               //bind second property to first
    System.out.println(second.get()); // '5'
    first.set(16);                    //set first property's value
    System.out.println(second.get()); // '16' - the value was automatically updated
}

आप जोड़, घटाव, विभाजन आदि को लागू करने के साथ एक आदिम संपत्ति को भी बांध सकते हैं:

public void test2()
{
        second.bind(first.add(100));
        System.out.println(second.get()); //'105'
        second.bind(first.subtract(50));
        System.out.println(second.get()); //'-45'
}

किसी भी वस्तु को SimpleObjectProperty में डाला जा सकता है:

SimpleObjectProperty<Color> color=new SimpleObjectProperty<>(Color.web("45f3d1"));

द्विदिश बाइंडिंग बनाना संभव है। इस मामले में, गुण एक दूसरे पर निर्भर करते हैं।

public void test3()
{
        second.bindBidirectional(first);
        System.out.println(second.get()+" "+first.get());
        second.set(1000);
        System.out.println(second.get()+" "+first.get()); //both are '1000'
}


Modified text is an extract of the original Stack Overflow Documentation
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow