JavaFX TableView doesn't show the content

I'm trying to insert some values in a TableView, but it doesn't display the text in the columns, even though they're not empty because there are three rows (the same number of items I inserted in the TableView) which are clickable.

我可以选择原料,但我看不到它们

I have the class "ClientiController" which is the controller of the fxml file, and these are the declaration of the TableView and the columns of the 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 call on the initialize() method a function, called loadTable() that adds the content to the TableView.

loadTable is in the same class "ClientiController" and this 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 class Cliente I have these strings:

private String id, nome, cognome, n_tel;

And the get and set functions for each String element, which take the values from the Database. In this Class I also have the readAll method ( ReadClienti ). In List<Cliente> clienti in the function loadTable() there is the result of the readAll method, and the function returns an ArrayList<ArrayList<String>> type.

If I select the first raw (even if I cannot see the text inside the columns) and then print it like this,

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

it all works fine and it prints the value I inserted as first, so I know the values are actually in that table.

I also tried to change the private String strings in this class into SimpleStringProperty like I saw in other discussions in here but nothing changed.

How can I make the tableView display its content?

Edit: I think the problem is in the assignment

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

in the first raw of loadTable(), because I cannot cast a type ArrayList<ArrayList<String>> into a List<String> . But the ObservableList<String> in which I have to put the values to populate the ListView only gets Lists or simple ArrayLists as input. How can I transform my ArrayList<ArrayList<String>> variable to match the ObservableList type?

链接地址: http://www.djcxy.com/p/80150.html

上一篇: 如何用List <Object>的行填充TableView?

下一篇: JavaFX TableView不显示内容