title: JavaFX : Consuming REST service and displaying the data in front-end
body: <p>I am working on a JavaFX(On JDK8 with SceneBuilder) project which should connect with a Spring-MVC based server and I would like to access some Objects from the server and display it. I have already programmed the Spring server to give back the desired object upon request, but my unfamiliarity in UI programming and JavaFX is making it a bit difficult. </p>
  
  <p>In the FXML file, I already have added a grid-pane and I would like to display the objects there. I would appreciate any help from you guys to get started up. I have only basic code, but I am pasting it below :</p>
  
  <p>Canvas.fxml :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;?import javafx.scene.control.*?&gt;
  &lt;?import java.lang.*?&gt;
  &lt;?import javafx.scene.layout.*?&gt;
  &lt;?import javafx.geometry.Insets?&gt;
  &lt;?import javafx.scene.layout.GridPane?&gt;
  &lt;?import javafx.scene.control.Button?&gt;
  &lt;?import javafx.scene.control.Label?&gt;
  
  &lt;GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8"&gt;
    &lt;columnConstraints&gt;
      &lt;ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /&gt;
      &lt;ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /&gt;
    &lt;/columnConstraints&gt;
    &lt;rowConstraints&gt;
      &lt;RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /&gt;
      &lt;RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /&gt;
      &lt;RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /&gt;
    &lt;/rowConstraints&gt;
  &lt;/GridPane&gt;
  </code></pre>
  
  <p>CanvasModel class :</p>
  
  <pre><code>public class Canvas {
  
      private int canvasid;
  
      private final StringProperty canvasName;
  
      private final StringProperty canvasTitle;
  
      private final StringProperty canvasImage;
  
      private byte[] canvasImageInBytes;
  
  
      public Canvas(String canvasName, String canvasTitle, String canvasImage){
          this.canvasName = new SimpleStringProperty(canvasName);
          this.canvasTitle = new SimpleStringProperty(canvasTitle);
          this.canvasImage = new SimpleStringProperty(canvasImage);
      }
  //Getters and setters ommitted
  }
  </code></pre>
  
  <p>Main class :</p>
  
  <pre><code>public class Main extends Application {
  
      private Stage primaryStage;
  
      @Override
      public void start(Stage primaryStage) throws Exception{
         Parent root = FXMLLoader.load(getClass().getResource("../View/mainui.fxml"));
  
  primaryStage.setTitle("CheckAPP");
         primaryStage.setScene(new Scene(root, 300, 600));
          primaryStage.setFullScreen(false);
          primaryStage.setMaximized(false);
  
          primaryStage.show();
      }
      public static void main(String[] args) {
          launch(args);
      }
  
      public Stage getPrimaryStage() {
          return this.primaryStage;
      }
  
  }
  </code></pre>
  
  <p>Now making a request to below :</p>
  
  <pre><code>http://localhost:8080/canvaslist
  </code></pre>
  
  <p>It will return a java.util.List which I want to display in GridPane. The images are in String format. I understand this is not a regular question like this is not working and all, but I am trying to wrap around my head for UI programming, and I didn't knew where else to turn to. Thanks a lot for your help.</p>