Avoid adding same object from mutableListOf to JPanel

I have a mutableListOf custom JButton that contains info of saved recipe files, when I click a button I want to go through all the saved recipe files and add them to the list as a button. After that I want to pick a random button from the list and add it to the JPanel.

So far so good, but when I want to make sure that not the same button gets added again, nothing that I’ve tried for the last couple hours have worked…

Tldr: Upon clicking a button I want to loop through saved files, add each to a list as a JButton, add a random list item to a JPanel whilst removing the previous one and make sure the same list item doesn’t get added twice in a row

Here’s my Github: https://github.com/lliinnkk10/FOE/blob/master/src/main/kotlin/com/github/atheera/recipemanager/gui/panels/recipe/RandomRecipePanel.kt

The function can be found at 157

submitted by /u/atheera
[link] [comments]