我尝试填充包含两列(名称和电子邮件)的TableView,但列仍为空。
这是控制器代码:
public class GUIMainController
{
@FXML private TableView<Member> tableMembers;
@FXML private TableColumn<Member, String> tcMemberName;
@FXML private TableColumn<Member, String> tcMemberEmail;
public void initialize()
{
tcMemberName.setCellValueFactory(new PropertyValueFactory<Member, String>("name"));
tcMemberEmail.setCellValueFactory(new PropertyValueFactory<Member, String>("email"));
tableMembers.setItems(getList());
}
public ObservableList<Member> getList()
{
ObservableList<Member> members = FXCollections.observableArrayList();
members.add(new Member("Frank","frankie678@gmail.com"));
System.out.println(members);
return members;
}
}
数据的构造函数:
public Member(String name, String email)
{
this.name = name;
this.email = email;
}
public String getMemberName()
{
return this.name;
}
public void setMemberName(String name)
{
this.name = name;
}
public String getMemberEmail()
{
return this.email;
}
public void setMemberEmail(String email)
{
this.email = email;
}
我可以在控制台上看到正确的数据,但它没有在表格中显示。
有人可以帮忙吗?提前谢谢!
答案 0 :(得分:0)
谢谢,我最终删除了我的getter和setter并在Eclipse中生成它们。工作就像一个魅力!