Tableview javaFX - The type of getColumns() is eroneous

给你一囗甜甜゛ 提交于 2020-01-17 12:24:49

问题


I have a problem with a getColumns error I simply can't figure out myself. I have searched the internet with no luck. I hope some of you have a great answer for this! Because I am stuck...

I have created a Create Member scene where I want to store the information in a TableView after it has been created. I have made a class called Person which makes the getters and setters.

In my TableView class I have made a TableView ArrayList which should hold the objects, but with NO luck!

The code is below and I hope you can help me. Sorry for the bad explanation. I am tired and MAD :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;


    }

}

My other class, Person:

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;
}



}

Hope you can help me ! The problem is in the: tableMembers.getColoums().addAll()

Regards, Alexander


回答1:


Try TableColumn<Person,String> instead of TableColumn



来源:https://stackoverflow.com/questions/30145135/tableview-javafx-the-type-of-getcolumns-is-eroneous

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!