Right now I use DefaultListModel with the wanted list of strings and I display it, via JList, in a JScrollPane.
What I want is to find a specific word in this sentence and to put an imageIcon instead of this word which I will display in the said JScrollPane.
For example I want to replace the word "cat" with a cat icon and the Strings would be:
"the little cat is good"
"there is no tomorrow"
"cat is what I need"
and my desired output will be a JScrollPane with the items:
"the little *cat icon* is good"
"there is no tomorrow"
"*cat icon* is what I need"
What I found are suggestions to create a custom ListCellRenderer to replace the DefaultListModel. In all the examples an imageIcon was added as icon to a lable, unfortunately this only adds one icon at the beginning of the text which is not what I desire.
Here is the relevant part from one of the examples from this site:
@Override
public Component getListCellRendererComponent(
JList list, Object value, int index,
boolean isSelected, boolean cellHasFocus) {
// Get the renderer component from parent class
JLabel label =
(JLabel) super.getListCellRendererComponent(list,
value, index, isSelected, cellHasFocus);
// Get icon to use for the list item value
Icon icon = icons.get(value);
// Set icon to display for value
label.setIcon(icon);
return label;
}
So, how can I add an icon inside a text in a JList ?
Any suggestions would be appreciated. Thank you

iconsmap contains and the values of theJList? - TitusJLabel's text if there is an icon for that value. Something like:if(icon!=null){label.setText("");}- Titus