问题
I'm making a media player in JavaFX. I'm displaying the songs in a TableView object. And whenever I press the Skip button, I would like it to highlight the next row, so that the user can see which song from the playlist, that he is listening to.
This is the code for the TableView.
I would like it to get the selected element, and then select/highlight the next element for me, whenever a certain method gets invoked.
@FXML
private TableView<Song> defaultTableView;
// 1) Song Title
@FXML
private TableColumn<Song, String> songTitleColumn;
// 2) Song artist
@FXML
private TableColumn<Song, String> songArtistColumn;
// 3) Song album
@FXML
private TableColumn<Song, String> songAlbumColumn;
回答1:
Call selectNext
on the selectionModel
of the table:
defaultTableView.getSelectionModel().selectNext();
The selection model also allows you to replace the selection with the selection of a specific item index using clearAndSelect
.
来源:https://stackoverflow.com/questions/54179474/how-to-select-highlight-next-row-in-tableview-javafx