palexdev / MaterialFX

A library of material components for JavaFX
GNU Lesser General Public License v3.0
1.21k stars 122 forks source link

how are you plane use setSelection method? #222

Closed deni5n closed 2 years ago

deni5n commented 2 years ago

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 commented 2 years ago
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?

palexdev commented 2 years ago

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

stale[bot] commented 2 years ago

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] commented 2 years ago

Closed for inactivity.