Вопрос

In the database I have 5 records created which are in a tableview. I can select 5 rows but the data is not shown in the tableView. I've tried everything, can anyone help?

The code of my problem:

initialize

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


}

class 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();
    }

}
Это было полезно?

Решение

You are using wrong method names as James_D suggested in the comment. Maybe a bit more in detail:

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

is linked to getClienteNome() in your ClientRow class (which does not exist). So you will have to rename getclientNome() to getClienteNome()

Same for the other methods. If this helped, don't forget to upvote James_D's comment.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top