javafx - How to create tabs dinamically keeping its content -


i trying create tabs dinamically. textfields, labels, buttons, etc keep position in tab. problem tab appears content empty. using fxml and, reading other post, tried create fxml new tabs don't know how.

rellenarcamposmascota method wold create tabs dinamically.

package mrpuppy.controller.cliente;  import java.io.ioexception;  import java.util.collection;   import org.springframework.beans.factory.annotation.autowired;  import org.springframework.stereotype.controller;   import javafx.event.actionevent;  import javafx.event.eventhandler;  import javafx.fxml.fxml;  import javafx.fxml.fxmlloader;  import javafx.scene.parent;  import javafx.scene.scene;  import javafx.scene.control.button;  import javafx.scene.control.combobox;  import javafx.scene.control.radiobutton;  import javafx.scene.control.tab;  import javafx.scene.control.tabpane;  import javafx.scene.control.textarea;  import javafx.scene.control.textfield;  import javafx.scene.layout.borderpane;  import javafx.scene.layout.pane;  import javafx.stage.modality;  import javafx.stage.stage;  import mrpuppy.dto.applicationcontextdto; import mrpuppy.entity.cliente; import mrpuppy.entity.mascota; import mrpuppy.service.clienteservice;  @controller public class editarclientecontrollerimpl implements editarclientecontroller  {  private stage primarystage; private scene scene; private fxmlloader loader; private final string css = this.getclass().getresource("/css/editarcliente.css").toexternalform();  @autowired private clienteservice clienteservice; @autowired private listaclientescontroller listaclientescontroller;  private int inttabs=0; private tab[] opentabs;  @fxml private tabpane tabpane; @fxml private tab tabmascota;  @fxml private textfield fieldnombrecliente; @fxml private textfield fieldapellidos; @fxml private textfield fielddni; @fxml private textfield fieldtelmovil; @fxml private textfield fieldtelfijo; @fxml private textfield fielddireccion; @fxml private textfield fieldcorreo;  @fxml private combobox<string> combomascota; @fxml private combobox<string> combotamano; @fxml private textfield fieldnombremascota; @fxml private radiobutton radioalergiasi; @fxml private radiobutton radioalergiano; @fxml private textfield fieldraza; @fxml private textfield fieldpeso; @fxml private combobox<string> combosexo; @fxml private combobox<string> comboagresividad; @fxml private textarea areaobservaciones;  @fxml private button buttoncancelareditarcliente; @fxml private button buttonaceptareditarcliente;  private applicationcontextdto applicationcontextdto;  @override public void openwindow(cliente cliente)  {     try     {         primarystage = new stage();         primarystage.setresizable(false);         loader = new fxmlloader(getclass().getresource("/view/editarcliente.fxml"));         loader.setcontroller(this);     //establecemos esta clase como "controller"         scene = loader.load();         scene.getstylesheets().add(css);         primarystage.setscene(scene);         primarystage.initmodality(modality.application_modal);         primarystage.show();         rellenarcamposcliente(cliente);         rellenarcamposmascota(cliente);          buttoncancelareditarcliente.setonaction(new eventhandler<actionevent>()                   {                         @override                         public void handle(actionevent event)                         {                             primarystage.close();                         }                   });          buttonaceptareditarcliente.setonaction(new eventhandler<actionevent>()                   {                         @override                         public void handle(actionevent event)                         {                             cliente.setnombre(fieldnombrecliente.gettext());                             cliente.setapellidos(fieldapellidos.gettext());                             cliente.setdni(fielddni.gettext());                             cliente.settelefonomovil(integer.parseint(fieldtelmovil.gettext()));                             cliente.settelefonofijo(integer.parseint(fieldtelfijo.gettext()));                             cliente.setdireccion(fielddireccion.gettext());                             cliente.setcorreo(fieldcorreo.gettext());                             clienteservice.actualizarcliente(cliente);                             primarystage.close();                         }                   });     }     catch(ioexception ioe)     {         system.out.println(ioe.getmessage());     } }   private void rellenarcamposcliente(cliente cliente) {     applicationcontextdto = new applicationcontextdto();     applicationcontextdto.setclienteservice();     clienteservice = applicationcontextdto.getclienteservice();      fieldnombrecliente.settext(cliente.getnombre());     fieldapellidos.settext(cliente.getapellidos());     fielddni.settext(cliente.getdni());     fieldtelmovil.settext(string.valueof(cliente.gettelefonomovil()));     fieldtelfijo.settext(string.valueof(cliente.gettelefonofijo()));     fielddireccion.settext(cliente.getdireccion());     fieldcorreo.settext(cliente.getcorreo());      return;  }   private void rellenarcamposmascota(cliente cliente) {        try     {              collection<mascota> mascotas = cliente.getmascotas();             for(mascota mascota : mascotas)             {                 tab newtab = new tab();                 loader = new fxmlloader(getclass().getresource("/view/mascotatab.fxml"));                 newtab.setcontent(loader.load());                 tabpane.gettabs().add(new tab());                 fieldnombremascota.settext(mascota.getnombre());                 fieldraza.settext(mascota.getraza());                 combosexo.setvalue(mascota.getsexo());                 fieldpeso.settext(string.valueof(mascota.getpeso()));                 combotamano.setvalue(mascota.gettamano());                 comboagresividad.setvalue(mascota.getagresividad());                 areaobservaciones.settext(mascota.getobservaciones());              }      }     catch(ioexception ioe)     {         system.out.println(ioe.getmessage());     }   }  } 

cliente tab must static.

<?xml version="1.0" encoding="utf-8"?>  <?import javafx.collections.fxcollections?> <?import java.lang.string?> <?import javafx.scene.control.button?> <?import javafx.scene.control.combobox?>  <?import javafx.scene.control.datepicker?>  <?import javafx.scene.control.label?>  <?import javafx.scene.control.radiobutton?> <?import javafx.scene.control.tab?> <?import javafx.scene.control.tabpane?> <?import javafx.scene.control.textarea?> <?import javafx.scene.control.textfield?> <?import javafx.scene.control.togglegroup?> <?import javafx.scene.layout.anchorpane?> <?import javafx.scene.layout.borderpane?> <?import javafx.scene.layout.hbox?> <?import javafx.scene.layout.vbox?> <?import javafx.scene.scene?>   <scene width="550" height="350" xmlns:fx="http://javafx.com/fxml"> <borderpane id="root">     <top>         <tabpane fx:id="tabpane">             <tabs>                 <tab fx:id="tabcliente" text="cliente" >                     <content>                         <anchorpane fx:id="panecliente">                             <vbox fx:id="vboxbloquecliente">                                 <children>                                     <hbox fx:id="hboxnombreapellidos">                                         <children>                                             <label fx:id="labelnombre" text="nombre:"/>                                             <textfield fx:id="fieldnombrecliente"/>                                              <label fx:id="labelapellidos" text="apellidos:"/>                                             <textfield fx:id="fieldapellidos"/>                                                  </children>                                     </hbox>                                     <hbox fx:id="hboxdnimovil">                                         <children>                                             <label fx:id="labeldni" text="dni:"/>                                             <textfield fx:id="fielddni"/>                                             <label fx:id="labeltelmovil" text="teléfono móvil:"/>                                             <textfield fx:id="fieldtelmovil"/>                                         </children>                                                              </hbox>                                     <hbox fx:id="hboxfijodireccion">                                         <children>                                             <label fx:id="labeltelfijo" text="teléfono fijo:&#10;(opcional)"/>                                             <textfield fx:id="fieldtelfijo"/>                                                <label fx:id="labeldireccion" text="dirección:"/>                                             <textfield fx:id="fielddireccion"/>                                                                                                          </children>                                     </hbox>                                     <hbox fx:id="hboxcorreo">                                         <children>                                             <label fx:id="labelcorreo" text="correo:"/>                                             <textfield fx:id="fieldcorreo"/>                                                                         </children>                                     </hbox>                                     <hbox fx:id="hboxbotonescliente">                                         <children>                                             <button fx:id="buttoncancelareditarcliente" text="cancelar"/>                                             <button fx:id="buttonaceptareditarcliente" text="confirmar"/>                                         </children>                                     </hbox>                                 </children>                             </vbox>                         </anchorpane>                     </content>                 </tab>                   <tab fx:id="tabmascota" text="mascota x" >                     <content>                         <anchorpane fx:id="paneeditarmascota">                             <vbox fx:id="vboxbloqueeditarmascota">                                 <children>                                     <hbox fx:id="hboxmascotatamano">                                         <children>                                             <combobox fx:id="combomascota">                                                 <items>                                                     <fxcollections fx:factory="observablearraylist">                                                         <string fx:value="perro" />                                                         <string fx:value="gato" />                                                     </fxcollections>                                                 </items>                                                     <value>                                                         <string fx:value="seleccionar mascota" />                                                     </value>                                             </combobox>                                             <combobox fx:id="combotamano">                                                 <items>                                                     <fxcollections fx:factory="observablearraylist">                                                         <string fx:value="pequeño" />                                                         <string fx:value="mediano" />                                                         <string fx:value="grande" />                                                     </fxcollections>                                                 </items>                                                     <value>                                                         <string fx:value="seleccionar tamaño" />                                                     </value>                                             </combobox>                                         </children>                                     </hbox>                                     <hbox fx:id="hboxnombrealergia">                                         <fx:define>                                             <togglegroup fx:id="groupalergia"/>                                         </fx:define>                                         <children>                                             <label fx:id="labelnombremascota" text="nombre:"/>                                             <textfield fx:id="fieldnombremascota"/>                                                  <label fx:id="labelalergico" text="alergico:"/>                                             <radiobutton fx:id="radioalergiasi" text="si" togglegroup="$groupalergia"/>                                             <radiobutton fx:id="radioalergiano" text="no" togglegroup="$groupalergia"/>                                         </children>                                     </hbox>                                     <hbox fx:id="hboxraza">                                         <children>                                             <label fx:id="labelraza" text="raza:"/>                                             <textfield fx:id="fieldraza"/>                                               <label fx:id="labelpeso" text="peso:"/>                                             <textfield fx:id="fieldpeso"/>                                                           </children>                                     </hbox>                                     <hbox fx:id="hboxsexoagresividad">                                         <children>                                             <combobox fx:id="combosexo">                                                 <items>                                                     <fxcollections fx:factory="observablearraylist">                                                         <string fx:value="macho" />                                                         <string fx:value="hembra" />                                                     </fxcollections>                                                 </items>                                                     <value>                                                         <string fx:value="seleccionar sexo" />                                                     </value>                                             </combobox>                                             <combobox fx:id="comboagresividad">                                                 <items>                                                     <fxcollections fx:factory="observablearraylist">                                                         <string fx:value="tranquilo" />                                                         <string fx:value="nervioso" />                                                         <string fx:value="agresivo" />                                                     </fxcollections>                                                 </items>                                                     <value>                                                         <string fx:value="seleccionar agresividad" />                                                     </value>                                             </combobox>                                         </children>                                     </hbox>                                     <hbox fx:id="hboxobservaciones">                                         <textarea fx:id="areaobservaciones"/>                                     </hbox>                                     <hbox fx:id="hboxbotonesanadirmascota">                                         <button fx:id="buttonvolveranadirmascota"/>                                         <button fx:id="buttonhomeanadirmascota"/>                                         <button fx:id="buttonanadirmascota"/>                                     </hbox>                                 </children>                             </vbox>                         </anchorpane>                     </content>                 </tab>             </tabs>         </tabpane>     </top> </borderpane> </scene> 

this tabs fxml file code, label returns error. don't know why.

<?xml version="1.0" encoding="utf-8"?>   <?import javafx.collections.fxcollections?> <?import java.lang.string?> <?import javafx.scene.control.button?> <?import javafx.scene.control.combobox?> <?import javafx.scene.control.datepicker?> <?import javafx.scene.control.label?> <?import javafx.scene.control.radiobutton?> <?import javafx.scene.control.tab?> <?import javafx.scene.control.tabpane?> <?import javafx.scene.control.textarea?> <?import javafx.scene.control.textfield?>  <?import javafx.scene.control.togglegroup?> <?import javafx.scene.layout.anchorpane?> <?import javafx.scene.layout.borderpane?> <?import javafx.scene.layout.hbox?> <?import javafx.scene.layout.vbox?> <?import javafx.scene.scene?>   <borderpane> <label fx:id="labelraza" text="raza:"/> </borderpane> 


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -