JavaFXBean_ObjectProperty1
  • Object converted to String
    Label label4 = new Label(prop1.get());
    Label label5 = new Label(prop2.get());
    Label label6 = new Label(prop3.asString().get());
    Label label7 = new Label(oemp1.asString().get());
Code :

package javafxtemplate1;
// ObjectProperty;
import javafx.application.Application;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.scene.control.Label;
import javafx.scene.layout.TilePane;
import javafx.scene.layout.VBox;

/**
*
* @author Manas9
*/
public class JavaFXTemplate1 extends Application {
//

@Override

public void start(Stage primaryStage)
{
//
// Group groot = new Group();
VBox groot = new VBox();
EMP2 emp2 = new EMP2();
Emp1 emp1 = new Emp1("John", "Smith", 2500.25);
emp2.setfirstName("John");
emp2.setlastName("Smith");
emp2.setSalary(2500.55);
//
StringProperty prop1 = new SimpleStringProperty("");
prop1.bindBidirectional(emp1.firstNameProperty());
StringProperty prop2 = new SimpleStringProperty("");
prop2.bindBidirectional(emp1.lastNameProperty());
DoubleProperty prop3 = new SimpleDoubleProperty();
prop3.bindBidirectional(emp1.salaryproperty());
//
ObjectProperty<Emp1> oemp1 = new SimpleObjectProperty<>(emp1);
//
Label label1 = new Label(emp2.getfirstName());
Label label2 = new Label(emp2.getlastName());
Label label3 = new Label(emp2.getSalary().toString());
//
Label label4 = new Label(prop1.get());
Label label5 = new Label(prop2.get());
Label label6 = new Label(prop3.asString().get());
Label label7 = new Label(oemp1.asString().get());
Label label8 = new Label("----as an object-------");
//
TilePane tPane1 = new TilePane(); // scenelayout package FlowPane
TilePane tPane2 = new TilePane();
TilePane tPane3 = new TilePane();
tPane1.setVgap(20); tPane1.setHgap(20);
tPane2.setVgap(20); tPane2.setHgap(20);
tPane3.setVgap(20); tPane3.setHgap(20);
//
tPane3.getChildren().addAll(label8,label7);
tPane2.getChildren().addAll(label4, label5, label6);
tPane1.getChildren().addAll(label1, label2, label3);
//

//
groot.getChildren().addAll(tPane1, tPane2, tPane3);
Scene scene = new Scene(groot, 300, 250, Color.WHITE);
primaryStage.setTitle("Properties :: Binding");
primaryStage.setScene(scene);
primaryStage.show();
}

public static void main(String[] args) {
launch(args);

}

}


// classs Emp1
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package javafxtemplate1;

import javafx.beans.property.DoubleProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;



/**
*
* @author Manas14
*/
public class Emp1 {
//
private final StringProperty firstName;
private final StringProperty lastName ;
private final DoubleProperty Salary;
public Emp1(String firstName, String lastName, Double salary) {
this.firstName = new SimpleStringProperty(firstName);
this.lastName = new SimpleStringProperty(lastName);
this.Salary = new SimpleDoubleProperty(salary);
}
//
public double getSalary(){
return Salary.get();
}
public void setSalary(Double Salary){
this.Salary.set(Salary);
}
public DoubleProperty salaryproperty()
{
return Salary;
}
//
public String getFirstName() {
return firstName.get();
}
//
public void setFirstName(String firstName) {
this.firstName.set(firstName);
}

public StringProperty firstNameProperty() {
return firstName;
}

public String getLastName() {
return lastName.get();
}

public void setLastName(String lastName) {
this.lastName.set(lastName);
}

public StringProperty lastNameProperty() {
return lastName;
}

@Override
public String toString() {
return (getFirstName() + " "
+ getLastName() + " " + getSalary());
}

}
//class EMP2

package javafxtemplate1;

import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

/**
*
* @author Manas14
*/
public class EMP2 {
private String firstName; private String lastName;
private Double Salary;
public EMP2(){ // no parameters
}
/*
private EMP2(String fName, String lName, Double pSal) {
this.firstName = new SimpleStringProperty(fName);
this.lastName = new SimpleStringProperty(lName);
this.Salary = new SimpleDoubleProperty(pSal);
}
*/
public String getfirstName() {
return firstName;
}
public void setfirstName(String fName) {
this.firstName =fName;
}

public String getlastName() {
return lastName;
}
public void setlastName(String lName) {
this.lastName =lName;
}

public Double getSalary() {
return Salary;
}
public void setSalary(Double pSal) {
this.Salary = pSal;
}
}