我正在尝试在TableView中插入一些值,但它不显示列中的文本,即使它们不是空的,因为有三行(我在TableView中插入的项目数相同)是点击 .
我有类“ClientiController”,它是fxml文件的控制器,这些是TableView的声明和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
我在initialize()方法上调用了一个名为loadTable()的函数,它将内容添加到TableView中 .
loadTable在同一个类“ClientiController”中,这是它的实现:
@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();
}
}
在类 Cliente
中我有这些字符串:
private String id, nome, cognome, n_tel;
以及每个String元素的get和set函数,它们从数据库中获取值 . 在这个类中我也有readAll方法( ReadClienti
) . 在函数 loadTable()
的 List<Cliente> clienti
中,有readAll方法的结果,该函数返回 ArrayList<ArrayList<String>>
类型 .
如果我选择第一个原始(即使我看不到列中的文本),然后像这样打印,
ArrayList<String> person = (ArrayList<String>) clientitable.getSelectionModel().getSelectedItem();
System.out.println(person);
它一切正常,它打印我插入的值作为第一,所以我知道值实际上在该表中 .
我也尝试将此类中的私有String字符串更改为SimpleStringProperty,就像我在此处的其他讨论中看到的那样,但没有任何改变 .
如何让tableView显示其内容?
Edit: 我认为问题在于作业
List<String> clienti = (List<String>) fc.processRequest("ReadClienti");
在loadTable()的第一个原始中,因为我无法将 ArrayList<ArrayList<String>>
类型转换为 List<String>
. 但是我必须将值放在ListView中的_1370618只获取Lists或简单的ArrayLists作为输入 . 如何转换 ArrayList<ArrayList<String>>
变量以匹配ObservableList类型?
1 回答
你的 class "Cliente"没有getter和setter . 并且还要注意参数的getter和setter的名称 . getter和setter不应与上面声明的参数不同 .
例如:
这行代码需要类的getter和setter ......