title: JavaFX: Nested Tables
body: <p>It is possible to create a table that contains other subtables in javafx like in the picture?</p>
  
  <p><a href="https://i.stack.imgur.com/cTyjU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cTyjU.png" alt="enter image description here"></a></p>
  
  <p>The program in the photo is written in javafx only that it is closed source.</p>
  
  <p>Is there any other external or internal component in java that allows me to create a similar interface?</p>
  
  <p>My problem is the same as this: <a href="https://stackoverflow.com/questions/39110036/javafx-tableview-open-detail-information-between-rows-on-click">JavaFX TableView: open detail information between rows on click</a>
  However, i need to load different value in the sub tables for every row. How can i do this?</p>
  
  <p>This is the creation of my sub-tabs.</p>
  
  <pre><code>private Node createDetailsPane(ObjectProperty&lt;Model&gt; item) {
      VBox vBox = new VBox();
  
      ObservableList&lt;Model&gt; dv = FXCollections.observableArrayList();
      ObservableList&lt;Model&gt; dl = FXCollections.observableArrayList();
      ObservableList&lt;Model&gt; dp = FXCollections.observableArrayList();
  
      TableView visite = new TableView();
      TableView latte = new TableView();
      TableView parti = new TableView();
  
      visite.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
      latte.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
      parti.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
  
      visite.setTableMenuButtonVisible(true);
      latte.setTableMenuButtonVisible(true);
      parti.setTableMenuButtonVisible(true);
  
      visite.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
      latte.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
      parti.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
  
      visite.getColumns().addAll(idVisita, dataVisita, azioniTerapeutiche, descrizioneVisita, incinta, dataPrevistaParto, veterinario);
      latte.getColumns().addAll(idLatte, litri, dataProduzione);
      parti.getColumns().addAll(idParto, dataParto, azioniParticolari);
  
      visite.setFixedCellSize(25);
      visite.prefHeightProperty().bind(visite.fixedCellSizeProperty().multiply(Bindings.size(visite.getItems()).add(2)));
      visite.minHeightProperty().bind(visite.prefHeightProperty());
      visite.maxHeightProperty().bind(visite.prefHeightProperty());
  
      latte.setFixedCellSize(25);
      latte.prefHeightProperty().bind(latte.fixedCellSizeProperty().multiply(Bindings.size(latte.getItems()).add(2)));
      latte.minHeightProperty().bind(latte.prefHeightProperty());
      latte.maxHeightProperty().bind(latte.prefHeightProperty());
  
      parti.setFixedCellSize(25);
      parti.prefHeightProperty().bind(parti.fixedCellSizeProperty().multiply(Bindings.size(parti.getItems()).add(2)));
      parti.minHeightProperty().bind(parti.prefHeightProperty());
      parti.maxHeightProperty().bind(parti.prefHeightProperty());
  
      parti.setItems(dp);
      latte.setItems(dl);
  
      String id;
      if(treeView.getSelectionModel().getSelectedIndices().get(treeView.getSelectionModel().getSelectedItems().size()-1) != -1) {
          id = treeView.getSelectionModel().getSelectedItems().get(treeView.getSelectionModel().getSelectedItems().size()-1).getIdProv();
          try {
              Connection conn = Driver.connection();
              conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/animali?autoReconnect=true&amp;useSSL=false", "admin", "admincs97");
              Statement stmt = conn.createStatement();
  
              sql = "SELECT DISTINCT `ID_VISITA`,`DATA_VISITA`,`AZIONI_TERAPEUTICHE`,`DESCRIZIONE_VISITA`,`STATO_VISITA`,`GRAVIDA_DA_GG`,`DATA_PREVISTA_PARTO`,`VETERINARIO` FROM `visite` "
                      + "LEFT JOIN `anagrafe` USING(`ID_PROVVISORIO`, `BOLO`) "
                      + "LEFT JOIN `parti` USING(`ID_PROVVISORIO`, `BOLO`) "
                      + "LEFT JOIN `latte` USING(`ID_PROVVISORIO`, `BOLO`) "
                      +where;
              String temp = "";
              if(where.trim().length() &gt; 0)
                  temp += " AND visite.`ID_PROVVISORIO` = '"+id+"'";
              else
                  temp = "WHERE visite.`ID_PROVVISORIO` = '"+id+"'";
  
              sql += temp;
  
              ResultSet rs = stmt.executeQuery(sql);
  
              if(rs.next())
                  do {
                      dv.add(new Model( rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getString(6), rs.getString(7), rs.getString(8)));
                      /*rs.getString(13), rs.getString(14), rs.getString(15), rs.getString(16), rs.getString(17), rs.getString(18), 
                      rs.getString(19), rs.getString(20), rs.getString(21), rs.getString(22), rs.getString(23), rs.getString(24), 
                      rs.getString(25), rs.getString(26) */
                  } while(rs.next());
          } catch(SQLException e) {
              new FxDialogs().showException("Errore", "Errore nel caricamento dei dati", e);
          }
      }
  
      visite.setItems(dv);
      vBox.getChildren().addAll(visite, latte, parti);
      return vBox ;
  }
  </code></pre>
  
  <p>Everything works until I select multiple rows in the main table.</p>
  
  <p>If for example I have two main lines, if I select first the second and then the first the subtables give me back the same value.</p>
  
  <p><a href="https://i.stack.imgur.com/C0SPo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/C0SPo.png" alt="enter image description here"></a></p>