title: JavaFx : How to put ImageView inside ListView
body: <p>I've been searching some threads about JavaFx ListView still it's hard to look for a simple yet easy solution for putting a JavaFx ImageView inside JavaFx ListView. I am trying to create a chat application using JavaFx framework. at the photo it should look like that.This is not duplicate because the other thread is vague for a beginner like me. <a href="http://i.stack.imgur.com/0fyzn.png" rel="noreferrer">ListView with imageview inside</a></p>
  
  <p>I tried something like this. I'm totally noob to this thanks in advance!</p>
  
  <pre><code>import javafx.application.Application;
  import javafx.collections.FXCollections;
  import javafx.collections.ObservableList;
  import javafx.scene.Scene;
  import javafx.scene.control.ListCell;
  import javafx.scene.control.ListView;
  import javafx.scene.image.Image;
  import javafx.scene.image.ImageView;
  import javafx.scene.layout.Priority;
  import javafx.scene.layout.VBox;
  import javafx.stage.Stage;
  
  public class Main extends Application {
       ImageView imageView = new ImageView();
       Image image = new Image(Main.class.getResourceAsStream("bell.jpg"));
      ListView&lt;String&gt; list = new ListView&lt;String&gt;();
      ObservableList&lt;String&gt; data = FXCollections.observableArrayList(
              "chocolate", "salmon", "gold", "coral", "darkorchid",
              "darkgoldenrod", "lightsalmon", "black", "rosybrown", "blue",
              "blueviolet", "brown");
     Image pic;
  
      @Override
      public void start(Stage stage) {
          VBox box = new VBox();
          Scene scene = new Scene(box, 200, 200);
          stage.setScene(scene);
          stage.setTitle("ListViewSample");
          box.getChildren().addAll(list);
          VBox.setVgrow(list, Priority.ALWAYS);
          list.setItems(data);
  
          list.setCellFactory(listView -&gt; new ListCell&lt;String&gt;() {
              public void updateItem(String friend, boolean empty) {
                  super.updateItem(friend, empty);
                  if (empty) {
                      setText(null);
                      setGraphic(null);
                  } else {
  
                      imageView.setImage(image);
                      setText(friend);
                      setGraphic(imageView);
                  }
              }
  
          });
  
          stage.show();
      }
  
  
      public static void main(String[] args) {
          launch(args);
      }
  }`
  </code></pre>