JavaFX8: How to create listener for selection of row in Tableview?

前端 未结 5 1382
广开言路
广开言路 2020-12-24 05:56

I currently have two tableviews in one screen, which results in both TableViews have rows which the user can select.

Now I want only one row to be selected at the sa

5条回答
  •  爱一瞬间的悲伤
    2020-12-24 06:51

    My solution would be creating custom cell factory for table and set it for each table columns.

    Callback, TableCell<..., ...>> value = param -> {
                    TextFieldTableCell cell = new TextFieldTableCell<>();
                    cell.addEventFilter(MouseEvent.MOUSE_CLICKED, event -> {
                                //your code
                            }
                    );
                    return cell;
                };
                packageName.setCellFactory(value);
    
        table1.column1.setCellFactory();
        table2.column1.setCellFactory();
        ...
    

提交回复
热议问题