JavaFX TableView不显示内容
我正在尝试在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函数,它们从数据库中获取值. 如果我选择第一个原始(即使我看不到列中的文本),然后像这样打印, ArrayList<String> person = (ArrayList<String>) clientitable.getSelectionModel().getSelectedItem(); System.out.println(person); 它一切正常,它打印我插入的值作为第一,所以我知道值实际上在该表中. 我也尝试将此类中的私有String字符串更改为SimpleStringProperty,就像我在此处的其他讨论中看到的那样,但没有任何改变. 如何让tableView显示其内容? 编辑: List<String> clienti = (List<String>) fc.processRequest("ReadClienti"); 在loadTable()的第一个原始中,因为我无法转换类型ArrayList< ArrayList< String>>到列表< String>. 解决方法
你的班级“Cliente”没有getter和setter.并且还要注意参数的getter和setter的名称. getter和setter不应与上面声明的参数不同.
例如: private String Clienteid; private String ClienteName; public getClientid(){ return Clienteid; } 这行代码需要类的getter和setter …… id.setCellValueFactory(new PropertyValueFactory<Cliente,String>("id")); nome.setCellValueFactory(new PropertyValueFactory<Cliente,String>("nome")); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |