diff --git a/src/main/java/musicplayer/PlayerGUI.java b/src/main/java/musicplayer/PlayerGUI.java index 41fc35d..f038616 100644 --- a/src/main/java/musicplayer/PlayerGUI.java +++ b/src/main/java/musicplayer/PlayerGUI.java @@ -158,7 +158,8 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf @Override public void setSongHighlighting(Song playingSong) { int index = playlistTableModel.getSongIndex(playingSong); - SwingUtilities.invokeLater(() -> playList.setRowSelectionInterval(index, index)); + if(index >= 0) + SwingUtilities.invokeLater(() -> playList.setRowSelectionInterval(index, index)); playlistTableModel.setPlayingRow(index); } @@ -201,7 +202,10 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf playlistTableModel.removeSong(invalidSong); } - public void playerStopped(){ playlistTableModel.setPlayingRow(-1); } + public void playerStopped(){ + setSongHighlighting(player.getCurrentSong()); + playlistTableModel.setPlayingRow(-1); + } /** * Refresh the library with songs in the currently selected display format. diff --git a/src/main/java/musicplayer/swingmodels/PlaylistTableModel.java b/src/main/java/musicplayer/swingmodels/PlaylistTableModel.java index 1d28f19..dd7867c 100644 --- a/src/main/java/musicplayer/swingmodels/PlaylistTableModel.java +++ b/src/main/java/musicplayer/swingmodels/PlaylistTableModel.java @@ -114,6 +114,10 @@ public class PlaylistTableModel extends AbstractTableModel { if(songList.size() > index && index >= 0){ songList.remove(index); fireTableRowsDeleted(index, index); + if(index < playingRow) + playingRow--; + else if(playingRow == index) + playingRow = -1; } }