Tableview javaFX - getColumns()的类型是错误的 [英] Tableview javaFX - The type of getColumns() is eroneous

查看:167
本文介绍了Tableview javaFX - getColumns()的类型是错误的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个getColumns错误的问题,我根本无法弄清楚自己。我没有运气在互联网上搜索过。我希望你们中的一些人有一个很好的答案!因为我被卡住了...

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...

我创建了一个Create Member场景,我希望在创建后将信息存储在TableView中。我创建了一个名为Person的类,它构成了getter和setter。

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.

在我的TableView类中,我创建了一个TableView ArrayList,它应该保存对象,但没有运气!

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

代码如下,我希望你能帮助我。
对不起解释很抱歉。我累了,MAD:D

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;


    }

}

我的另一个类,Person:

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



}

希望你能帮助我!
问题在于:tableMembers.getColoums()。addAll()

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

问候,
Alexander

Regards, Alexander

推荐答案

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

这篇关于Tableview javaFX - getColumns()的类型是错误的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆