How to add elements to an ObservableList in JavaFx?

0

I am currently making a form where I want to store the record of a student of any institution, in that form I have a ComboBox that is "group" and in that Combo I would like to store information of the database on said table.

Group Model

package Modelo;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@Entity(name="grupo")
public class Grupo {

    @Id
    @GeneratedValue
    private int idGrupo;

    @Column(name="NombreG")
    private String nombre;

    @Column(name="CantidadA")
    private int cantidad;

    @Column(name="Grado")
    private String grado;

    @Column(name="Nivel")
    private float nivel;

    @Column(name="Nota")
    private String nota;

    @Column(name="Fecha")
    private Date fecha;

    @Column(name="IdPeriodo")
    private int id_periodo;


    public Grupo(int idGrupo, String nombre, int cantidad, String grado, float nivel, String nota, Date fecha,
            int id_periodo) {
        super();
        this.idGrupo = idGrupo;
        this.nombre = nombre;
        this.cantidad = cantidad;
        this.grado = grado;
        this.fecha = fecha;
        this.nivel = nivel;
        this.nota = nota;
        this.id_periodo = id_periodo;
    }

    public Grupo() {
        this(0,"",0,"",0.0f,"",new Date(),0);
    }

    public int getIdGrupo() {
        return idGrupo;
    }

    public void setIdGrupo(int idGrupo) {
        this.idGrupo = idGrupo;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public int getCantidad() {
        return cantidad;
    }

    public void setCantidad(int cantidad) {
        this.cantidad = cantidad;
    }

    public String getGrado() {
        return grado;
    }

    public void setGrado(String grado) {
        this.grado = grado;
    }

    public float getNivel() {
        return nivel;
    }

    public void setNivel(float nivel) {
        this.nivel = nivel;
    }

    public String getNota() {
        return nota;
    }

    public void setNota(String nota) {
        this.nota = nota;
    }

    public Date getFecha() {
        return fecha;
    }

    public void setFecha(Date fecha) {
        this.fecha = fecha;
    }

    public int getId_periodo() {
        return id_periodo;
    }

    public void setId_periodo(int id_periodo) {
        this.id_periodo = id_periodo;
    }



}

Group Controller

 @FXML
        private ComboBox<Grupo> cmbGrupo;
        private ObservableList<Grupo> grupos;

cmbGrupo = new ComboBox<>();
        grupos = FXCollections.observableArrayList();
        cmbGrupo.setItems(grupos);

When compiling the program I get the following:

    
asked by David 18.12.2016 в 00:45
source

1 answer

0

To add elements to the ComboBox you must use the method setItems (...) indicating the elements that it will contain, you can see a good example of how to use this control here: link

    
answered by 13.01.2017 в 16:14