javafx tableview columview with button I need that when clicking auto select the row

0

I need to click on the button that is already in a column to automatically select the row to be able to do get and set to the selected item. Otherwise, it generates nullpointer . I was thinking about adding a listener that when I click on the button, select the row directly, but I do not know.

This is a screenshot:

This is the code:

botonVisitar.setOnAction((ActionEvent event) -> {

    TextInputDialog dialog1 = new TextInputDialog();
    Stage stage1 = (Stage) dialog1.getDialogPane().getScene().getWindow();
    stage1.getIcons().add(new Image(this.getClass().getResource("icono.jpg").toString()));
    dialog1.setTitle("Visita:");
    dialog1.setContentText("Ingresar Tipo de visita: (por ejemplo: llamada, mail, mensaje, etc)");
    Optional<String> result1 = dialog1.showAndWait();
    if (result1.isPresent()) {

        TablaVisita.getSelectionModel().getSelectedItem().setTipoVisita(result1.get());
        TablaVisita.getSelectionModel().getSelectedItem().setFechaVisita(LocalDate.now());

        //si no esta selecionado me dice nullPointer. 
    }
    
asked by Lionel Rezoagli 10.03.2017 в 16:39
source

2 answers

0

I found the solution at link , I post it so that the resolution knows what is in trouble:

    botonVisitar.setOnAction((ActionEvent event) -> {

        ...

        if (result1.isPresent()) {
            MyItem item = (MyItem) getTableRow().getItem();

            item.setTipoVisita(result1.get());
            item.setFechaVisita(LocalDate.now());
        }
    });
    
answered by 25.03.2017 / 13:21
source
0

You do it the way you got it, you call it on the button onaction.

the get is easy:

Visita miVisita;

botonVisitar.setOnAction((ActionEvent event) -> {
  try{
    mivisita=TablaVisita.getSelectionModel().getSelectedItem();
  }
  catch(Exception ex){
    System.out.println("no se ha seleccionado una visita");
  }

}

In this case, you should never reach the catch, since all values are loaded from somewhere.

    
answered by 17.03.2017 в 18:20