如何在tableview中显示数据库的数据?

时间:2014-05-06 04:02:33

标签: java sql user-interface tableview javafx-8

在数据库中,我创建了5个记录在tableview中的记录。我可以选择5行,但数据不会显示在tableView中。我尝试了一切,有人可以帮忙吗?

我的问题代码:

初始化

public void initialize(URL arg0, ResourceBundle arg1) {
    colNome.setCellValueFactory(new PropertyValueFactory<ClientRow, String>(
            "clienteNome"));
    colRG.setCellValueFactory(new PropertyValueFactory<ClientRow, String>(
            "clienteRG"));
    colPlaca.setCellValueFactory(new PropertyValueFactory<ClientRow, String>(
            "clientePlaca"));
    colModelo.setCellValueFactory(new PropertyValueFactory<ClientRow, String>(
                        "clienteModelo"));
    colData.setCellValueFactory(new PropertyValueFactory<ClientRow, String>(
                "clienteData"));

    applyList(daoClient.getListDao());
}

applyList

private void applyList(List<Client> client) {

    ObservableList<ClientRow> listObservable =                FXCollections.observableArrayList();
    for (Client p : client) {
        String nome = p.getNome();
        String modelo = p.getModelo();
        String placa = p.getPlaca();
        String data = p.getDataInicio().toString();
        String rg = p.getRg();

        listObservable.add(new ClientRow(nome, modelo, placa, data, rg));
    }
    tableClient.setItems(listObservable);


}

类ClientRow

public class ClientRow {

    public final SimpleStringProperty clientNome;
    public final SimpleStringProperty clientRG;
    public final SimpleStringProperty clientPlaca;
    public final SimpleStringProperty clientModelo;
    public final SimpleStringProperty clientData;

    public ClientRow(String clientNome, String clientRG,
            String clientPlaca, String clientModelo, String clientData) {
        this.clientNome = new SimpleStringProperty(clientNome);
        this.clientRG = new SimpleStringProperty(clientRG);
        this.clientPlaca = new SimpleStringProperty(clientPlaca);
        this.clientModelo = new SimpleStringProperty(clientModelo);
        this.clientData = new SimpleStringProperty(clientData);
    }

    public String getclientNome() {
        return clientNome.get();
    }

    public String getclientRG() {
        return clientRG.get();
    }

    public String getclientPlaca() {
        return clientRG.get();
    }

    public String getclientModelo() {
        return clientModelo.get();
    }

    public String getclientData() {
        return clientData.get();
    }

}

1 个答案:

答案 0 :(得分:1)

您使用的错误方法名称正如James_D在评论中所建议的那样。也许更详细一点:

colNome.setCellValueFactory(new PropertyValueFactory<ClientRow, String>("clienteNome"));

链接到ClientRow类中的getClienteNome()(不存在)。因此,您必须将getclientNome()重命名为getClienteNome()

其他方法相同。如果这有帮助,请不要忘记赞成James_D的评论。