Search code examples
javaswingjlistlistcellrenderer

Java JList setting color of items


could you please help me, how to change color of items showed in JList?

I'm making an user JList where I can see online and offline users, and I need the offline users to have different colors than online users.

My code for creating users

final String [] strings=database.getUsers(myLogin);  

jList1.setModel(new javax.swing.AbstractListModel() {
     @Override
     public int getSize() { return strings.length; }
     @Override
     public Object getElementAt(int i) { return strings[i]; }
});

Solution