【发布时间】:2015-05-09 21:20:15
【问题描述】:
我遇到了一个 getColumns 错误问题,我自己也搞不清楚。我没有运气搜索过互联网。我希望你们中的一些人对此有一个很好的答案!因为我被卡住了……
我创建了一个创建成员场景,我想在创建后将信息存储在 TableView 中。我创建了一个名为 Person 的类,它可以生成 getter 和 setter。
在我的 TableView 类中,我创建了一个 TableView ArrayList,它应该保存对象,但没有运气!
代码如下,希望你能帮到我。 抱歉解释不好。我很累很生气:D
public class Members extends DelfinenProjekt
{
DelfinenProjekt df = new DelfinenProjekt();
private TableView<Person> tableMembers = new TableView<Person>();
private final Label memberLabel = new Label("Brugeroversigt");
private final VBox vbox = new VBox();
private final ObservableList<Person> memberData = FXCollections.observableArrayList(new Person(firstnameTextField.getText(),
lastnameTextField.getText(),
ageTextField.getText(),
addressTextField.getText(),
cityTextField.getText(),
emailMedlemTextField.getText(),
cprNoTextField.getText()));
public Scene members()
{
BorderPane border = new BorderPane();
border.setCenter(tableMembers);
memberLabel.setFont(new Font("Tahoma", 20));
tableMembers.setEditable(true);
// Creating table menu with coloums
TableColumn firstnameColoum = new TableColumn("Firstname");
firstnameColoum.setMaxWidth(100);
firstnameColoum.setCellValueFactory(new PropertyValueFactory<Person, String>("firstName"));
TableColumn lastnameColoum = new TableColumn("Lastname");
lastnameColoum.setMaxWidth(100);
lastnameColoum.setCellValueFactory(new PropertyValueFactory<Person, String>("lastName"));
TableColumn ageColoum = new TableColumn("Age");
ageColoum.setMaxWidth(100);
ageColoum.setCellValueFactory(new PropertyValueFactory<Person, String>("age"));
TableColumn addressColoum = new TableColumn("Address");
addressColoum.setMaxWidth(100);
addressColoum.setCellValueFactory(new PropertyValueFactory<Person, String>("address"));
TableColumn cityColoum = new TableColumn("City");
cityColoum.setMaxWidth(100);
cityColoum.setCellValueFactory(new PropertyValueFactory<Person, String>("city"));
TableColumn emailColoum = new TableColumn("Email");
emailColoum.setMaxWidth(100);
emailColoum.setCellValueFactory(new PropertyValueFactory<Person, String>("email"));
TableColumn cprColoum = new TableColumn("CPR number");
cprColoum.setMaxWidth(100);
cprColoum.setCellValueFactory(new PropertyValueFactory<Person, String>("cprNo"));
// Adding them to the getColoums in TableView
tableMembers.setItems(memberData);
tableMembers.getColumns().addAll(firstnameColoum, lastnameColoum, ageColoum, addressColoum, cityColoum, emailColoum, cprColoum);
vbox.setSpacing(5);
vbox.setPadding(new Insets(10));
vbox.getChildren().addAll(memberLabel, tableMembers);
Scene scene = new Scene(new Group(border), 640, 480);
((Group) scene.getRoot()).getChildren().addAll(vbox);
return scene;
}
}
我的另一个班级,人:
public class Person implements Serializable
{
private SimpleStringProperty firstName;
private SimpleStringProperty lastName;
private SimpleIntegerProperty age;
private SimpleStringProperty address;
private SimpleStringProperty city;
private SimpleStringProperty email;
private SimpleDoubleProperty cprNo;
public Person(String firstName, String lastName, int age, String address, String city, String email, double cprNo)
{
this.firstName = new SimpleStringProperty(firstName);
this.lastName = new SimpleStringProperty(lastName);
this.age = new SimpleIntegerProperty(age);
this.address = new SimpleStringProperty(address);
this.city = new SimpleStringProperty(city);
this.email = new SimpleStringProperty(email);
this.cprNo = new SimpleDoubleProperty(cprNo);
}
public SimpleStringProperty getFirstName() {
return firstName;
}
public void setFirstName(SimpleStringProperty firstName) {
this.firstName = firstName;
}
public SimpleStringProperty getLastName() {
return lastName;
}
public void setLastName(SimpleStringProperty lastName) {
this.lastName = lastName;
}
public SimpleIntegerProperty getAge() {
return age;
}
public void setAge(SimpleIntegerProperty age) {
this.age = age;
}
public SimpleStringProperty getAddress() {
return address;
}
public void setAddress(SimpleStringProperty address) {
this.address = address;
}
public SimpleStringProperty getCity() {
return city;
}
public void setCity(SimpleStringProperty city) {
this.city = city;
}
public SimpleStringProperty getEmail() {
return email;
}
public void setEmail(SimpleStringProperty email) {
this.email = email;
}
public SimpleDoubleProperty getCprNo() {
return cprNo;
}
public void setCprNo(SimpleDoubleProperty cprNo) {
this.cprNo = cprNo;
}
}
希望你能帮助我! 问题出在:tableMembers.getColoums().addAll()
问候, 亚历山大
【问题讨论】:
标签: java uitableview javafx javafx-2