public static Set<Object> highlightDuplicates(JList list) {
        Set<Object> listElements = new HashSet<Object>();

        DefaultListModel model = (DefaultListModel) list.getModel();
        ListSelectionModel sm = list.getSelectionModel();
        sm.clearSelection();
        model.trimToSize();
        for (Object element : model.toArray()) {
            if (listElements.contains(element)) {
                selectAllElementsLike(list, element.toString(), null);
            } else {
                listElements.add(element);
            }
        }
        return listElements;
    }