Access all rows of a JAVAFX table

Asked

Viewed 157 times

0

I have the following table:

inserir a descrição da imagem aqui

When clicking a button, I want a function to run on each line read:

    private void inserirResultadosUsuario() {
    //Necessário pegar o valor de cada linha e de cada coluna por  vez              
}

Complete controller code:

@FXML private Button btnSalvar;
@FXML private TableView<Partida> tabela;   
@FXML private TextField txtRodada;
@FXML private Button btnRodadas;
@FXML private TableColumn<Partida, String> clmTime1;
@FXML private TableColumn<Partida, Integer> clmPlacar1;
@FXML private TableColumn<String, String> clmX;
@FXML private TableColumn<Partida, Integer> clmPlacar2;
@FXML private TableColumn<Partida, String> clmTime2;

public void initialize(URL location, ResourceBundle resources) {

    clmTime1.setCellValueFactory(new PropertyValueFactory<>("cod_time1"));
    clmPlacar1.setCellValueFactory(new PropertyValueFactory<>("gol_time1"));
    clmX.setCellValueFactory(new PropertyValueFactory<>("X"));
    clmPlacar2.setCellValueFactory(new PropertyValueFactory<>("gol_time2"));
    clmTime2.setCellValueFactory(new PropertyValueFactory<>("cod_time2"));      
}

@FXML
private void refreshTable() {
    ArrayList<Partida> listaPartida = new partidaDAO().listarPartidas();
    ObservableList<Partida> observableList = FXCollections.observableArrayList(listaPartida);
    tabela.setItems(observableList);        
}

@FXML
private void mostrarTabelaDeAcordoComRodada() {
    int i = Integer.parseInt(txtRodada.getText());
    ArrayList<Partida> listarPartidaEspecifica = partidaDAO.listarPartidasEspecifica(i);
    ObservableList<Partida> observableList = FXCollections.observableArrayList(listarPartidaEspecifica);
    tabela.setItems(observableList);
}

@FXML
private void inserirResultadosUsuario() {

}

How could I do that?

1 answer

1

This table consists of a list of some item, So : List<Item> lista ;

In the method that is called by your button you will do the following :

itens.forEach(item -> inserirResultadosUsuario());

So there is the guarantee that for each item in this list the insert method has been executed.

  • I took a look here and could not visualize how to make this change, I changed the original post with the full controller, can take a look?

  • tries the following table.getItems(). foreach(item -> insertResults(); Says if there is an error

Browser other questions tagged

You are not signed in. Login or sign up in order to post.