所以我有一个Person类:
package tableview;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleStringProperty;
public class Person {
private SimpleStringProperty name;
private SimpleBooleanProperty smart;
public Person(String name, boolean smart) {
this.name = new SimpleStringProperty(name);
this.smart = new SimpleBooleanProperty(smart);
}
public SimpleStringProperty getName() {
return name;
}
public void setName(SimpleStringProperty name) {
this.name = name;
}
public SimpleBooleanProperty getSmart() {
return smart;
}
}
这就是我将它们添加到ObservableList of Persons
的方法 person.add(new Person("Emre", false));
这就是我设置CellValueFactory
的方法 nameColumn.setCellValueFactory(new PropertyValueFactory<Person, String>("name"));
这些是
列@FXML
public TableColumn<Person, String> nameColumn;
@FXML
public TableColumn<Person, Boolean> smartColumn;
但它在表格视图中显示了这个
无论如何都要显示名称的字符串?
答案 0 :(得分:1)
试试这个
public String getName() {
return name.get();
}
public boolean getSmart() {
return smart.get();
}