getValueAt () in javafx

0

I want to capture the contents of a specific cell in my table, in jtable I did it with:
myTable.getValueAt (int row, int column);

How can I do it in javaFX?

My code:

//Archivo controlador de la app.
public class FXMLDocumentController implements Initializable {
    @FXML private TableView <Proceso> tablaInfo;
    @FXML private TableColumn columnaId;
    @FXML private TableColumn columnaNombre;
    @FXML private TableColumn columnaQuantum;
    @FXML private TableColumn columnaRecursos;
    @FXML private TableColumn columnaEstado;
    @FXML private TableColumn columnaTiempo;  
    ObservableList<Proceso> lista;

    @FXML private void botonIniciarClicked(ActionEvent event) {
        for (int i = 1 ; i < 13 ; i++){
            int Q = (int)((Math.random()*29)+1);
            Proceso proceso = new Proceso();
            proceso.id.set(i);
            proceso.nombre.set("Proceso "+i);
            proceso.quantum.set(Q);
            proceso.recursos.set(1);         
            proceso.estado.set("Ejecutando");
            proceso.tiempo.set(1);
            lista.add(proceso);    
        }

    public void Procesar(int cont){
        int idProcesar = tablaInfo.getValueAt(cont,0);
        //Aqui surge el error, "cannot find symbol method getValueAt()"
    }

}



//-----------------------Clase Proceso----------------------
public class Proceso{
    public SimpleIntegerProperty id = new SimpleIntegerProperty();
    public SimpleStringProperty nombre = new SimpleStringProperty();
    public SimpleIntegerProperty quantum = new SimpleIntegerProperty();
    public SimpleDoubleProperty recursos = new SimpleDoubleProperty();
    public SimpleStringProperty estado = new SimpleStringProperty();
    public SimpleIntegerProperty tiempo = new SimpleIntegerProperty();

    public Integer getId() {
        return id.get();
    }
    public String getNombre() {
        return nombre.get();
    }
    public Integer getQuantum() {
        return quantum.get();
    }
    public Double getRecursos() {
        return recursos.get();
    }
    public String getEstado() {
        return estado.get();
    }
    public Integer getTiempo() {
        return tiempo.get();
    }
}
    
asked by Gabo Reyes 10.04.2017 в 22:58
source

2 answers

2

Actually in JavaFX the philosophy of the tables completely changes, it does not look at all like a JTable with a TableView.

// to get the name for example, I do row by row of the table and then cognate the value of the column I want

for (int i = 0; i < tbView.getItems().size(); i++)
    System.out.println(tbView.getItems().get(i).getNombre().toString());                   

Also forget that you can do it this way, with a nested for, one to go through the rows and the other for the columns that are visible

for (int i = 0; i < tbView.getItems().size(); i++)                        
    for (TableColumn column : tbView.getVisibleLeafColumns())            
        System.out.println(column.getCellData(i));
    
answered by 10.05.2017 в 23:07
0

According to your example, you would have to modify the 'Process' method of the following way:

public void Procesar(int cont){
    Proceso proc = tablaInfo.getItems().get(cont);
    int idProcesar = proc.getId();
    .
    .
    .
}

Each row of 'tableInfo' is an object of type 'Process'. First you get the object located in the row 'cont' and then you get the field you are interested in, in this case the 'id' field, using the method (property) getId () defined in the class (Process).

    
answered by 15.04.2017 в 08:27