Code example for JLabel

Methods: setIconsetText

0
        JLabel comp = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        if (!(value instanceof File))
            return comp;
        File file = (File) value;
        if (file.getName().endsWith(".jar") || file.getName().endsWith(".zip"))
            comp.setIcon(jarIcon);
        else 
            comp.setIcon(dirIcon);
        String fileName = file.getName();
        if (file.getParent() != null)
            fileName = fileName + " - " + file.getParent();
        comp.setText(fileName);
        return comp;
    } 
} 
Contextual code suggestions in your IDE  Get Codota for Java