gpt4 book ai didi

java - Tableview javaFX - getColumns() 的类型是错误的

转载 作者:行者123 更新时间:2023-12-01 11:34:27 24 4
gpt4 key购买 nike

我遇到了 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;


}

}

我的其他类(class),人员:

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()

问候,亚历山大

最佳答案

尝试TableColumn<Person,String>而不是TableColumn

关于java - Tableview javaFX - getColumns() 的类型是错误的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30145135/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com