How to set the style of list view cells based on a condition in JavaFX
<p>I am attempting to set the style of individual cells in a list view based on a condition. The list view is of type Label, and the condition is determined based on another class when labels are inserted into the listview. </p>

<p>Currently, I have tried to set the background colour of each label in the list view but it doesn't cover the entire area (see picture).</p>

<p><a href="https://i.stack.imgur.com/Tkgnn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Tkgnn.png" alt="enter image description here"></a></p>

<p>I've also researched this article but it doesn't suit my case as the identifier for highlighting the list view cell is not carried in the string.</p>

<p><a href="https://stackoverflow.com/questions/32696033/how-do-i-dynamically-change-the-background-of-an-item-in-a-listview-in-javafx">How do I dynamically change the background of an item in a listview in JavaFX</a> </p>

<p>Current code so far:</p>

<pre><code>for (Consultation c : notifications){
            Label l = new Label(": consult reminder - "  + c.getReminderTime());

            if(c.getReminderRead() == 1){ //if the consultation reminder hasn't been read
                l.setStyle("-fx-background-color: #33CEFF");
                counter = counter + 1;
            }


            notificationList.getItems().add(l);
}
</code></pre>

<p>any ideas?</p>