JavaFx - Comment afficher SimpleStringProperty valeur dans TableView

Je suis occupé à travailler à travers un didacticiel et je suis bloqué sur un point.

Fondamentalement lancement de la nouvelle scène et d'afficher les valeurs de ObservableList de type Personne dans un affichage tableau.

La personne de la classe se compose de 3 SimpleStringProperty de firsName, nom et e-mail.

Mais quand je lance l'application, elle semble afficher les valeurs de la SimpleStringProperty [StringProperty [valeur:valeur réelle]] dans le tableau et non pas la valeur de la SimpleStringProperty. Si je change la Personne de la classe getFirstName méthode pour renvoyer une Chaîne de prénom.get (), puis il affiche la valeur correctement dans le tableau.

Suis-je censé utiliser le SimpleStringProperty ou plutôt des objets simples comme des String?
JavaFx - Comment afficher SimpleStringProperty valeur dans TableView

La classe personne

package co.za.chrispie.addressBook;

import javafx.beans.property.SimpleStringProperty;

public class Person {

private SimpleStringProperty firstName;
private SimpleStringProperty lastName;
private SimpleStringProperty email;

public Person(final String firstName, final String lastName, final String email) {
    this.firstName = new SimpleStringProperty(firstName);
    this.lastName = new SimpleStringProperty(lastName);
    this.email = new SimpleStringProperty(email);
}

public String getFirstName() {
    return firstName.get(); //Changes this method to return a String
}

public SimpleStringProperty getLastName() {
    return lastName;
}

public SimpleStringProperty getEmail() {
    return email;
}

}

De la classe de Contrôleur

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package co.za.chrispie.addressBook;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
public class OracleAddressBookController implements Initializable {
@FXML
TableView<Person> table;
@FXML
TableColumn<Person, String> colFirstName;
@FXML
TableColumn<Person, String> colLastName;
@FXML
TableColumn<Person, String> colEmail;
final ObservableList<Person> data = FXCollections.observableArrayList(
new Person("Jaco", "Pieters", "[email protected]"),
new Person("Chrispie", "Pieters", "[email protected]")
);
@Override
public void initialize(URL url, ResourceBundle rb) {
assert colFirstName != null : "fx:id=\"colFirstName\" was not injected: check your FXML file 'OracleAddressBook.fxml'.";
assert colLastName != null : "fx:id=\"colLastName\" was not injected: check your FXML file 'OracleAddressBook.fxml'.";
assert colEmail != null : "fx:id=\"colEmail\" was not injected: check your FXML file 'OracleAddressBook.fxml'.";
configureTable();
}    
private void configureTable() {
colFirstName.setCellValueFactory(new PropertyValueFactory<Person, String>("firstName"));
colLastName.setCellValueFactory(new PropertyValueFactory<Person, String>("lastName"));
colEmail.setCellValueFactory(new PropertyValueFactory<Person, String>("email"));
table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
table.setItems(data);
assert table.getItems() == data;
}
}

et l'extrémité avant FXML

<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.net.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="500.0" prefWidth="600.0"    styleClass="mainFxmlClass" xmlns:fx="http://javafx.com/fxml"  fx:controller="co.za.chrispie.addressBook.OracleAddressBookController">
<children>
<Label layoutX="14.0" layoutY="11.0" text="Address Book" />
<TableView fx:id="table" layoutX="14.0" layoutY="35.0" prefHeight="451.0" prefWidth="572.0">
<columns>
<TableColumn prefWidth="75.0" text="First Name" fx:id="colFirstName" />
<TableColumn prefWidth="75.0" text="Last Name" fx:id="colLastName" />
<TableColumn prefWidth="75.0" text="Email" fx:id="colEmail" />
</columns>
</TableView>
</children>
<stylesheets>
<URL value="@oracleaddressbook.css" />
</stylesheets>
</AnchorPane>
J'ai trouvé cette explication utile: JavaFX Propriété ARchitecture

OriginalL'auteur Chrispie | 2012-11-22