MaterialFX icon indicating copy to clipboard operation
MaterialFX copied to clipboard

how are you plane use setSelection method?

Open deni5n opened this issue 4 years ago • 4 comments

I will need to render the selected row in "MFXTableView" when the user presses the right mouse button to display the context menu (by default, the row is not selected when the user presses the right mouse button). I see the method:

table.getSelectionModel().setSelection()

but that i can send him a parameter? can you provide an example?

deni5n avatar Jul 02 '22 15:07 deni5n

MFXTableColumn<User> idColumn = new MFXTableColumn<>("Id", true, Comparator.comparing(User::getId));
        idColumn.setRowCellFactory(user -> new MFXTableRowCell<>(User::getId) {{
            setOnMouseClicked(mouseEvent -> {
                ObservableMap<Integer, User> map = FXCollections.observableHashMap();
                int i = users.indexOf(user);
                map.put(i, user);
                table.getSelectionModel().setSelection(map);
                setContextMenu(menu(user));
            });
        }});

but context menu is not showing. perhaps the update is not synchronous and the context menu is overwritten?

deni5n avatar Jul 02 '22 16:07 deni5n

There is no context menu by default plus there's a much simpler way to allow selection with the right mouse button

For both you need a custom row you can extend MFXTableRow as it already offers everything you need Check both the documentation and the src code

palexdev avatar Jul 03 '22 13:07 palexdev

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 01 '22 17:08 stale[bot]

Closed for inactivity.

stale[bot] avatar Aug 08 '22 19:08 stale[bot]