Code example for JLabel

Methods: setIcon

0
        setEnabled(tree.isEnabled());
        _text.setText(stringValue);
        _text.setSelect(isSelected);
        _text.setFocus(hasFocus);
        if (leaf) {
            _icon.setIcon(UIManager.getIcon("Tree.leafIcon"));
        } else if (expanded) {
            _icon.setIcon(UIManager.getIcon("Tree.openIcon"));
        } else { 
            _icon.setIcon(UIManager.getIcon("Tree.closedIcon"));
        } 
        return this;
    } 
     
    public Dimension getPreferredSize() {
        Dimension iconD = _icon.getPreferredSize();
        Dimension textD = _text.getPreferredSize();
        int height = iconD.height < textD.height ?
        textD.height : iconD.height;
        return new Dimension(iconD.width + textD.width, height);
Connect your IDE to all the code out there  Get Codota for Java