@FXML private void initialize(){ // метод нужен для работы contactForList.fieldData();// чтобы метод получил данные из коллекции contactForList.getContactList()); // нужен что бы ListView мог принимать коллекцию из другого класса listContact.setCellFactory(new Callback<ListView<Contact>, ListCell<Contact>>() { @Override public ListCell<Contact> call(ListView<Contact> param) { //тут нужно собрать объект ListCellContact, и вернуть его ListCell<Contact> listCell = new ListCell<Contact>() { @Override protected void updateItem(Contact item, boolean empty) { super.updateItem(item, empty); if (empty || item == null) { setText(null); setGraphic(null); } else { //тут нужно загрузить fxml файл // пробовал способом ниже , но не получается FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/view/boxInContact.fxml")); fxmlLoader.setController(this); labelName.setText(item.getName()); lblSense.setText(item.getSense()); lblStatus.setText(item.getStatus()); avatar.setImage(item.getImage()); } } }; return listCell; } }); listContact.setItems((ObservableList) contactForList.getContactList()); } 

    1 answer 1

    You did almost everything right, but you didn’t get the root of the loaded fxml

     @Override protected void updateItem(Contact item, boolean empty) { super.updateItem(item, empty); if (empty || item == null) { setText(null); setGraphic(null); } else { //тут нужно загрузить fxml файл // пробовал способом ниже , но не получается FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/view/boxInContact.fxml")); fxmlLoader.setController(this); labelName.setText(item.getName()); lblSense.setText(item.getSense()); lblStatus.setText(item.getStatus()); avatar.setImage(item.getImage()); setGraphic((Node) fxmlLoader.getRoot()); // добавьте эту строчку } } 

    But I can immediately say that you will have to load fxml'ка always when you call updateItem , and this happens quite often (when scrolling, for example), in this connection, the application may hang, because You will download fxml in the same stream. Therefore, I advise you to consider any alternatives.