Created
December 7, 2015 15:08
-
-
Save JohnnyQQQQ/ebb132c8d92dec21f0a7 to your computer and use it in GitHub Desktop.
binding a simple java object to javafx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javafx.beans.property.StringProperty; | |
import javafx.beans.property.adapter.JavaBeanStringPropertyBuilder; | |
public class Main { | |
public static class MyPojo { | |
private String name; | |
private String country; | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
public String getCountry() { | |
return country; | |
} | |
public void setCountry(String country) { | |
this.country = country; | |
} | |
} | |
private static MyPojo myPojo = new MyPojo(); | |
public static void main(String[] args) throws NoSuchMethodException { | |
myPojo.setName("Test"); | |
myPojo.setCountry("Senegal"); | |
StringProperty nameProperty = JavaBeanStringPropertyBuilder.create() | |
.bean(myPojo) | |
.name("name") | |
.build(); | |
StringProperty countryProperty = JavaBeanStringPropertyBuilder.create() | |
.bean(myPojo) | |
.name("country") | |
.build(); | |
// output inital values | |
System.out.println(nameProperty.get()); | |
System.out.println(myPojo.name); | |
// change value to "Eduard" | |
nameProperty.setValue("Eduard"); | |
// both values has been changed to "Eduard" | |
System.out.println(nameProperty.get()); | |
System.out.println(myPojo.name); | |
// same for country field | |
System.out.println(countryProperty.get()); | |
System.out.println(myPojo.country); | |
countryProperty.setValue("Germany"); | |
System.out.println(countryProperty.get()); | |
System.out.println(myPojo.country); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment