JavaFX tableview does not display content

I'm trying to insert some values in tableview, but it doesn't display the text in the column, even if they are not empty, because three rows (the same number of items I insert in tableview) click

I have a class "clienticontroller", which is the controller of the fxml file. These are the declarations of tableview and the columns of tableview

@FXML // fx:id="clientitable"
private TableView clientitable; // Value injected by FXMLLoader

@FXML // fx:id="nome"
private TableColumn nome; // Value injected by FXMLLoader

@FXML // fx:id="id"
private TableColumn id; // Value injected by FXMLLoader

@FXML // fx:id="telefono"
private TableColumn telefono; // Value injected by FXMLLoader

I called a function called loadtable () in the initialize () method, which adds content to tableview

Loadtable is in the same class "clienticontroller", which is its implementation:

@FXML
void loadTable()
{
    //Cliente
    try {
        List<String> clienti = (List<String>) fc.processRequest("ReadClienti");
        ObservableList<String> clienteData = FXCollections.observableArrayList(clienti);

        id.setCellValueFactory(new PropertyValueFactory<Cliente,String>("id"));
        nome.setCellValueFactory(new PropertyValueFactory<Cliente,String>("nome"));
        cognome.setCellValueFactory(new PropertyValueFactory<Cliente,String>("cognome"));
        telefono.setCellValueFactory(new PropertyValueFactory<Cliente,String>("n_tel"));


        System.out.println(clienteData);
        clientitable.setItems(clienteData);

        } catch (SecurityException | NoSuchMethodException
            | ClassNotFoundException | InstantiationException
            | illegalaccessexception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } 
}

In the cliente class, I have these strings:

private String id,nome,cognome,n_tel;

And the get and set functions of each string element, which get values from the database I also have a readall method (readclienti) in this class In the list < client >, the clientile in the function loadtable() has the result of the readall method, and the function returns an ArrayList < ArrayList < string > > type

If I select the first original (even if I can't see the text in the column) and print like this,

ArrayList<String> person =  (ArrayList<String>) clientitable.getSelectionModel().getSelectedItem();
System.out.println(person);

It's all right. It prints the value I inserted as the first, so I know the value is actually in the table

I also tried to change the private string in this class to simplestringproperty, as I saw in other discussions here, but nothing changed

How to make tableview display its contents?

Editor: I think the problem is homework

List<String> clienti = (List<String>) fc.processRequest("ReadClienti");

In the first primitive of loadtable(), because I cannot convert the type ArrayList < ArrayList < string > > to list < string > But observablelist < string > I have to put the value in listview to get the list or simple ArrayLists as input How do I convert my ArrayList < ArrayList < string > > variables to match the observablelist type?

Solution

Your class "client" has no getter and setter Also note the names of getters and setters of parameters Getters and setters should not differ from the parameters declared above

private String Clienteid;
private String ClienteName;

public getClientid(){
    return Clienteid;
}

This line of code needs the getter and setter of the class

id.setCellValueFactory(new PropertyValueFactory<Cliente,String>("id"));
nome.setCellValueFactory(new PropertyValueFactory<Cliente,String>("nome"));
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>