Java 8 ListCellRenderer - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ListCellRenderer class.

This code example shows how to use the following methods:getListCellRendererComponent
        this.delegate = delegate;
    } 
 
    public Component getListCellRendererComponent(JList list, Object value,
            int index, boolean isSelected, boolean cellHasFocus) {
        Component comp = delegate.getListCellRendererComponent(list, value,
                index, isSelected, cellHasFocus);
        if (index != -1 && addSeparatorAfter(list, value, index)) {
            separatorPanel.removeAll();
            separatorPanel.add(comp, BorderLayout.CENTER);
            separatorPanel.add(separator, BorderLayout.NORTH);
            return separatorPanel;
        } else 
            return comp;
    } 
 
    protected abstract boolean addSeparatorAfter(JList list, Object value,
            int index);
} 
3
CodeRank
This code example shows how to use the following methods:getListCellRendererComponent
                                                boolean isSelected,
                                                boolean cellHasFocus) {
    if (index == -1)
      return null; 
 
    JLabel label = (JLabel) renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    if (gap < 0)
      gap = label.getIconTextGap();
     
    Icon icon = IconUtil.getIcon(value);
 
    if (icon == null) {
      label.setIcon(emptyIcon);
    } 
    else { 
      label.setIcon(icon);
      label.setIconTextGap(gap + width - icon.getIconWidth());
    } 
 
    return label;
3
CodeRank
This code example shows how to use the following methods:getListCellRendererComponent
            rep = nullRep_; 
        } 
        else { 
            rep = mapValue( value ); 
        } 
        Component comp = baseRenderer_
                        .getListCellRendererComponent( list, rep, index, 
                                                       isSelected, hasFocus );
        String descrip = value instanceof StarTableColumn
                       ? ((StarTableColumn) value).getColumnInfo() 
                                                  .getDescription() 
                       : null; 
        if ( comboBox_ != null ) {
            if ( descrip != null && descrip.trim().length() == 0 ) {
                descrip = null;
            } 
            comboBox_.setToolTipText( descrip );
        } 
        return comp;
    } 
4
CodeRank
This code example shows how to use the following methods:getListCellRendererComponent
    } 
 
    public static ListCellRenderer applyFontRenderer(final ListCellRenderer underlyingRenderer) {
        return new ListCellRenderer() {
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                Component rendered = underlyingRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
 
                Font f = (Font) value;
 
                rendered.setFont(f);
 
                if (rendered instanceof JLabel) {
                    JLabel jLabel = (JLabel) rendered;
                    jLabel.setText(index + " " + f.getName());
                } 
 
                return rendered;
            } 
        }; 
    } 
3
CodeRank
This code example shows how to use the following methods:getListCellRendererComponent
     */ 
    public Component getListCellRendererComponent( JList list, Object value,
                                                   int index,
                                                   boolean isSelected,
                                                   boolean hasFocus ) {
        Component c =
            renderer_.getListCellRendererComponent( list, value, index,
                                                    isSelected, hasFocus );
        if ( c instanceof JLabel ) {
            ((JLabel) c).setText( getRendererText( value ) );
            ((JLabel) c).setIcon( getRendererIcon( value ) );
        } 
        return c;
    } 
} 
4
CodeRank
This code example shows how to use the following methods:getListCellRendererComponent
        } 
        else { 
            rep = mapValue( value ); 
        } 
        return baseRenderer_
              .getListCellRendererComponent( list, rep, index,
                                             isSelected, hasFocus );
    } 
 
    /** 
     * Sets the representation for the <tt>null</tt> value. 
     * If set to a non-null value, this will be used to render a  
     * null; otherwise, {@link #mapValue} will be called as usual 
     * (which may itself do something with the null). 
     * 
     * @param  nullRep  null representation 
     */ 
    public void setNullRepresentation( Object nullRep ) { 
        nullRep_ = nullRep; 
    } 
4
CodeRank
This code example shows how to use the following methods:getListCellRendererComponent
   * Return the component that should be added to the tree hierarchy for 
   * this editor 
   */ 
  public Component getEditorComponent()
  { 
    final Component listCellRendererComponent = renderer.getListCellRendererComponent
        (new JList(), comboBox.getSelectedItem(), comboBox.getSelectedIndex(), false, comboBox.hasFocus());
    if (listCellRendererComponent instanceof JComponent)
    { 
      final JComponent jc = (JComponent) listCellRendererComponent;
      jc.setBorder(new LineBorder(Color.BLACK));
    } 
    return listCellRendererComponent;
  } 
 
  /** 
   * Set the item that should be edited. Cancel any editing if necessary * 
   */ 
  public void setItem(final Object item) 
  { 
4
CodeRank
This code example shows how to use the following methods:getListCellRendererComponent
            depth = 0;
            baseIcon = null;
        } 
 
        /* Re-use default behaviour. */ 
        Component comp =
            baseRenderer_.getListCellRendererComponent( list, value, index,
                                                        isSelected, hasFocus );
 
        /* Offset the icon according to how deep we are in the node 
         * hierarchy. */ 
        if ( comp instanceof JLabel && baseIcon != null ) {
            final int offset = 2 + ( ( index >= 0 ) ? depth * 10 : 0 );
            final Icon icon = new Icon() {
                public int getIconHeight() { 
                    return baseIcon.getIconHeight();
                } 
                public int getIconWidth() { 
                    return baseIcon.getIconWidth() + offset;
                } 
4
CodeRank
This code example shows how to use the following methods:getListCellRendererComponent
					else 
						renderedValue = value; 
				} 
				else 
					renderedValue = value; 
				return delegate.getListCellRendererComponent(list, renderedValue, index, isSelected, cellHasFocus);
			} 
		}; 
		return listCellRenderer;
	} 
 
	public static NamedObject[] fromEnum(Class<? extends Enum<?>> enumeration) {
		return fromEnum(enumeration.getSimpleName() + "." , enumeration);
	} 
	public static NamedObject[] fromEnum(final String prefix, Class<? extends Enum<?>> enumeration) {
		final Enum<?>[] enumConstants=enumeration.getEnumConstants();
		NamedObject[] objs = new NamedObject[enumConstants.length];
		int i = 0;
		for(Enum<?> value : enumConstants){
			objs[i++] = new NamedObject(value, TextUtils.getText(prefix + value.toString()));
4
CodeRank
This code example shows how to use the following methods:getListCellRendererComponent
See Code Examples for Java 8 ListCellRenderer Methods: