0

I need to click on the Image that is already in a column to automatically call a method. But I don't seem capable of doing it. I've got a class named worker, the tableview is set with an ObservableList of Worker objects that i obtain from a database.

Here's an image of mi table:

enter image description here

The images are an attribute of Worker class if anyone is wondering. They are for deleting and editing the rows.

Here's the code that I use to fill the tableview;

 @Override
    public void initialize(URL url, ResourceBundle rb) {
        DatabaseController dbc;
        dbc = new DatabaseController();
        dbc.connect();
        ObservableList<Empleado> empleados = dbc.selectEmpleados();

        columNombre.setCellValueFactory(new PropertyValueFactory<>("nombre"));
        columActivo.setCellValueFactory(new PropertyValueFactory<>("activo"));
        columApellidos.setCellValueFactory(new PropertyValueFactory<>("apellidos"));
        columDNI.setCellValueFactory(new PropertyValueFactory<>("dni"));
        columRango.setCellValueFactory(new PropertyValueFactory<>("rango"));
        columTelefono.setCellValueFactory(new PropertyValueFactory<>("telefono"));
        columEmail.setCellValueFactory(new PropertyValueFactory<>("email"));
        columID.setCellValueFactory(new PropertyValueFactory<>("id"));
        columRol.setCellValueFactory(new PropertyValueFactory<>("rol"));
        columEdit.setCellValueFactory(new PropertyValueFactory<>("edit"));
        columDelete.setCellValueFactory(new PropertyValueFactory<>("delete"));

        table_empleados.setItems(empleados);

    }
  • See https://stackoverflow.com/questions/46498649/add-two-button-in-one-column-and-get-the-click-row-value-javafx – James_D Jan 12 '18 at 13:04
  • I'd recommend using buttons rather than trying to create clickable images. You can use a cell factory to create the buttons, see [JavaFX table- how to add components?](https://stackoverflow.com/questions/16360323/javafx-table-how-to-add-components) – jewelsea Jan 12 '18 at 19:38

0 Answers0