我有以下代码从REST数据库中获取所有数据 我需要将该List放入javaFX TableView中 我见过的所有示例都使用带有tableobject.setItems(ObservableListObject)的ObservableList来填充TableView。 我遗漏了一些东西 - 似乎我的通用列表不兼容。 任何Sugestions?
编辑:澄清类:是实体类pojo。
public class Customers implements Serializable {
下面的是FMXLController类
public class CustomerFXMLController {
@FXML
private TableView<?> customerTable;
@FXML
private TableColumn<?, ?> columnId;
@FXML
private TableColumn<?, ?> columnName;
@FXML
private TableColumn<?, ?> columnLastName;
private Customers customer;
/* single customer class record*/
private CustomersJerseyClient client;
private List<Customers> customers;
@FXML
protected void initialize() {
client = new CustomersJerseyClient();
GenericType<List<Customers>> gType = new GenericType<List<Customers>>() {
};
Response response = client.findAll_JSON(Response.class);
customers = response.readEntity(gType);
customer = customers.get(customersIndex);
答案 0 :(得分:0)
假设想法是在表中显示Customers
个对象的集合(即表中的每一行包含一个Customers
实例),那么你应该相应地声明你的表和列:
@FXML
private TableView<Customers> customerTable ;
@FXML
private TableColumn<Customers, Number> columnId ;
@FXML
private TableColumn<Customers, String> columnName ;
等(我猜测列的类型,显然)。
然后你就可以了
customerTable.getItems().setAll(customers);
答案 1 :(得分:-1)
对此的正确解决方案不仅仅是上述答案。因为JavaFX需要使用可观察的东西,所以在具有setter和getter的pojo类CustomerTableModel中处理从String到StringProperty的转换。
@FXML private TableView<CustomerTableModel> customersTable;
@FXML
private TableColumn<CustomerTableModel, Number> columnId;
@FXML
private TableColumn<CustomerTableModel, String> columnName;
@FXML
private TableColumn<CustomerTableModel, String> columnLastName;
@FXML
private TableColumn<CustomerTableModel, String> columnMobileNumber;