Component (@NotNull JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { @SuppressWarnings({"unchecked"}) final JComponent comp = myFun.fun((T)value); comp.setOpaque(true); if (isSelected) { comp.setBackground(list.getSelectionBackground()); comp.setForeground(list.getSelectionForeground()); } else { comp.setBackground(list.getBackground()); comp.setForeground(list.getForeground()); } for (JLabel label : UIUtil.findComponentsOfType(comp, JLabel.class)) { label.setForeground(UIUtil.getListForeground(isSelected)); } return comp; }