'How to highlight specific row in JList?

So I have a JList of words and a search field. When they search for a word and press "Search" I'll scroll to their word by using:

for (int i = 0; i < slm.getSize(); i++) {
    if (slm.getElementAt(i).getKey().equals(searchText)) {
      jlist.ensureIndexIsVisible(i);
    //highlight row that contains searchText
    }
}

"slm" is a SortedListModel which is a class extending AbstractListModel.

Now I also here want to add a line so I can highlight the row where the word exists in the list. So I don't think this has to do with selectionListener since I just want to highlight the row and not obtain the content in any way. Is that correct? If not, I just want to do a very simple like: jlist.highlightRowAt("randomWord"); What's the closest thing I'll get to? Best if it can fit on just one row there below the ensure-method.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source