Java 类javax.swing.ListCellRenderer 实例源码

项目:incubator-netbeans    文件:EditRulesPanel.java   
private ListCellRenderer createSelectorsRenderer() {
        return new DefaultListCellRenderer() {
            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                if (value != null) {
                    SelectorItemRenderer selectorModelItemRenderer = getSelectorModelItemRenderer();
                    selectorModelItemRenderer.setItem((SelectorItem) value, isSelected);
                    return selectorModelItemRenderer;

//                    setText(item.getDisplayName());
                }
                return c;
            }
        };
    }
项目:incubator-netbeans    文件:CreateRulePanel.java   
/**
 * Creates a renderer for the at-rules combobox dropdown.
 */   
private ListCellRenderer createAtRulesRenderer() {
    return new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (value == null) {
                setText(Bundle.none_item());
            } else if(value instanceof AtRuleItem) {
                setText(((AtRuleItem) value).getDisplayName());
            } else if(value instanceof String) {
                setText((String)value);
            }
            return c;
        }
    };
}
项目:incubator-netbeans    文件:FileSearchAction.java   
@Override
@NonNull
public ListCellRenderer getListCellRenderer(
        @NonNull final JList list,
        @NonNull final Document nameDocument,
        @NonNull final ButtonModel caseSensitive,
        @NonNull final ButtonModel colorPrefered) {
    Parameters.notNull("list", list);   //NOI18N
    Parameters.notNull("nameDocument", nameDocument);   //NOI18N
    Parameters.notNull("caseSensitive", caseSensitive); //NOI18N
    return ItemRenderer.Builder.create(
                list,
                caseSensitive,
                new FileDescriptorConvertor(nameDocument)).
            setCamelCaseSeparator(CAMEL_CASE_SEPARATOR).
            setColorPreferedProject(colorPrefered).
            build();
}
项目:incubator-netbeans    文件:ModifyElementRulesPanel.java   
private ListCellRenderer createStyleSheetsRenderer() {
    return new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (value == null) {
                setText("<html>" + Bundle.none_item());
            } else {
                FileObject file = (FileObject) value;
                FileObject webRoot = ProjectWebRootQuery.getWebRoot(file);

                String file2string;
                if (webRoot != null) {
                    file2string = FileUtil.getRelativePath(webRoot, file);
                } else {
                    file2string = FileUtil.getFileDisplayName(file);
                }

                setText(file2string);
            }
            return c;
        }
    };
}
项目:incubator-netbeans    文件:FolderBasedOptionPanel.java   
/** Creates new form FolderBasedOptionPanel */
FolderBasedOptionPanel(FolderBasedController controller, Document filterDocument, boolean allowFiltering) {
    this.controller = controller;

    initComponents();

    filter.setDocument(filterDocument);

    if (!allowFiltering) {
        filter.setVisible(false);
        filterLabel.setVisible(false);
    }

    ListCellRenderer renderer = new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            if (value instanceof String)
                value = EditorSettings.getDefault().getLanguageName((String)value);
            return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        }
    };
    languageCombo.setRenderer(renderer);
    languageCombo.addActionListener(this);

    update();
}
项目:marathonv5    文件:JListItemJavaElement.java   
public static Component getRendererComponent(JList list, int item) {
    Object value = list.getModel().getElementAt(item);
    ListCellRenderer cellRenderer = list.getCellRenderer();
    Component rendererComponent = cellRenderer.getListCellRendererComponent(list, value, item, false, false);
    if (rendererComponent == null) {
        return null;
    }
    return rendererComponent;
}
项目:powertext    文件:DelegatingCellRenderer.java   
/**
 * {@inheritDoc}
 */
@Override
public Component getListCellRendererComponent(JList list, Object value,
                    int index, boolean selected, boolean hasFocus) {
    Completion c = (Completion)value;
    CompletionProvider p = c.getProvider();
    ListCellRenderer r = p.getListCellRenderer();
    if (r!=null) {
        return r.getListCellRendererComponent(list, value, index, selected,
                                                hasFocus);
    }
    if (fallback==null) {
        return super.getListCellRendererComponent(list, value, index,
                                            selected, hasFocus);
    }
    return fallback.getListCellRendererComponent(list, value, index,
                                                selected, hasFocus);
}
项目:word-constraints    文件:SepComboBox.java   
private ListCellRenderer createRenderer()
{
   return new DefaultListCellRenderer()
   {
      private final Component SEPARATOR = new SeparatorComponent();

      public Component getListCellRendererComponent( JList list,
            Object value, int index, boolean isSelected, boolean cellHasFocus)
      {
         if ( value instanceof ComboItem )
         {
            value = ((ComboItem)value).getDelegate();
         }

         if ( value == null )
         {
            return SEPARATOR;
         }
         return super.getListCellRendererComponent( list, value, index, 
               isSelected, cellHasFocus );
      }
   };
}
项目:openjdk-jdk10    文件:AquaComboBoxPopup.java   
protected Dimension getBestPopupSizeForRowCount(final int maxRowCount) {
    final int currentElementCount = comboBox.getModel().getSize();
    final int rowCount = Math.min(maxRowCount, currentElementCount);

    final Dimension popupSize = new Dimension();
    final ListCellRenderer<Object> renderer = list.getCellRenderer();

    for (int i = 0; i < rowCount; i++) {
        final Object value = list.getModel().getElementAt(i);
        final Component c = renderer.getListCellRendererComponent(list, value, i, false, false);

        final Dimension prefSize = c.getPreferredSize();
        popupSize.height += prefSize.height;
        popupSize.width = Math.max(prefSize.width, popupSize.width);
    }

    popupSize.width += 10;

    return popupSize;
}
项目:Neukoelln_SER316    文件:NotesList.java   
public ListCellRenderer getCellRenderer() {
       return new DefaultListCellRenderer()  {

    public Component getListCellRendererComponent(
      JList list,
      Object value,            // value to display
      int index,               // cell index
      boolean isSelected,      // is the cell selected
      boolean cellHasFocus)    // the list and the cell have the focus
    {
        JLabel label = (JLabel)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        String s = value.toString();
        label.setText(s);
        //Note currentNote = CurrentProject.getNoteList().getActiveNote();
     Note currentNote = CurrentNote.get();
        if (currentNote != null) {
           if (getNote(index).getId().equals(currentNote.getId()))
               label.setFont(label.getFont().deriveFont(Font.BOLD));
        }
        if (getNote(index).isMarked())
           label.setIcon(bookmarkIcon);
        //setIcon();
      /*if (isSelected) {
            setBackground(list.getSelectionBackground());
          setForeground(list.getSelectionForeground());
      }
        else {
          setBackground(list.getBackground());
          setForeground(list.getForeground());
      }
      setEnabled(list.isEnabled());
      setFont(list.getFont());
        setOpaque(true);*/
        label.setToolTipText(s);
        return label;
    }
   };

}
项目:incubator-netbeans    文件:EditRulesPanel.java   
private ListCellRenderer createAtRulesRenderer() {
    return new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (value == null) {
                setText(Bundle.EditRulesPanel_none_item());
            } else {
                setText(((MediaItem) value).getDisplayName());
            }
            return c;
        }
    };
}
项目:incubator-netbeans    文件:CreateRulePanel.java   
/**
 * Creates a renderer for the selectors combobox dropdown.
 */
private ListCellRenderer createSelectorsRenderer() {
    return new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (value != null) {
                if(value instanceof SelectorItem) {
                    SelectorItem selectorItem = (SelectorItem) value;
                    if (selectorItem == NO_CLASS || selectorItem == NO_ID) {
                        setText(Bundle.none_item());
                        return c;
                    } else {
                        SelectorItemRenderer selectorModelItemRenderer = getSelectorModelItemRenderer();
                        boolean originalElement = false;
                        switch (selectorItem.getType()) {
                            case SelectorItem.CLASS_TYPE:
                                originalElement = selectorItem.getItemName().equals(getSelectedElementClassName());
                                break;
                            case SelectorItem.ID_TYPE:
                                originalElement = selectorItem.getItemName().equals(getSelectedElementIdName());
                                break;
                        }
                        selectorModelItemRenderer.setItem(selectorItem, isSelected, originalElement);
                        return selectorModelItemRenderer;
                    }
                }
            } else if(value instanceof String) {
                setText((String)value);
            }
            return c;
        }
    };
}
项目:incubator-netbeans    文件:CreateRulePanel.java   
/**
 * Creates a renderer for the stylesheets combobox dropdown.
 */    
private ListCellRenderer createStylesheetsRenderer() {
    return new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (value == null) {
                //empty model
                return c;
            }
            if(value instanceof FileObject) {
                FileObject file = (FileObject) value;
                if(webRoot == null) {
                    setText(file.getNameExt());
                } else {
                    String relativePath = FileUtil.getRelativePath(webRoot, file);
                    if(relativePath != null) {
                        setText(relativePath);
                    } else {
                        //should not happen
                        setText(file.getNameExt());
                    }
                }
            } else if(value instanceof String) {
                setText((String)value);
            }

            return c;
        }
    };
}
项目:incubator-netbeans    文件:ViewTooltips.java   
private void showJList (JScrollPane view, Point pt) {
    JList list = (JList) view.getViewport().getView();
    Point p = SwingUtilities.convertPoint(view, pt.x, pt.y, list);
    int row = list.locationToIndex(p);
    if (row == -1) {
        hide();
        return;
    }
    Rectangle bds = list.getCellBounds(row, 
            row);
    //GetCellBounds returns a width that is the
    //full component width;  we want only what
    //the renderer really needs.
    ListCellRenderer ren = list.getCellRenderer();
    Dimension rendererSize = 
            ren.getListCellRendererComponent(list, 
            list.getModel().getElementAt(row), 
            row, false, false).getPreferredSize();

    bds.width = rendererSize.width;
    if (bds == null || !bds.contains(p)) {
        hide();
        return;
    }
    if (setCompAndRow (list, row)) {
        Rectangle visible = getShowingRect (view);
        Rectangle[] rects = getRects (bds, visible);
        if (rects.length > 0) {
            ensureOldPopupsHidden();
            painter.configure(
                    list.getModel().getElementAt(row), 
                    view, list, row);
            showPopups (rects, bds, visible, list, view);
        } else {
            hide();
        }
    }
}
项目:incubator-netbeans    文件:CategoryList.java   
private static ListCellRenderer getItemRenderer () {
    ListCellRenderer renderer = rendererRef == null ? null : rendererRef.get ();
    if (renderer == null) {
        renderer = new ItemRenderer ();
        rendererRef = new WeakReference<ListCellRenderer>( renderer );
    }
    return renderer;
}
项目:SER316-Aachen    文件:NotesList.java   
public ListCellRenderer getCellRenderer() {
       return new DefaultListCellRenderer()  {

    public Component getListCellRendererComponent(
      JList list,
      Object value,            // value to display
      int index,               // cell index
      boolean isSelected,      // is the cell selected
      boolean cellHasFocus)    // the list and the cell have the focus
    {
        JLabel label = (JLabel)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        String s = value.toString();
        label.setText(s);
        //Note currentNote = CurrentProject.getNoteList().getActiveNote();
     Note currentNote = CurrentNote.get();
        if (currentNote != null) {
           if (getNote(index).getId().equals(currentNote.getId()))
               label.setFont(label.getFont().deriveFont(Font.BOLD));
        }
        if (getNote(index).isMarked())
           label.setIcon(bookmarkIcon);
        //setIcon();
      /*if (isSelected) {
            setBackground(list.getSelectionBackground());
          setForeground(list.getSelectionForeground());
      }
        else {
          setBackground(list.getBackground());
          setForeground(list.getForeground());
      }
      setEnabled(list.isEnabled());
      setFont(list.getFont());
        setOpaque(true);*/
        label.setToolTipText(s);
        return label;
    }
   };

}
项目:incubator-netbeans    文件:ContentProviderImpl.java   
@Override
public ListCellRenderer getListCellRenderer(
        @NonNull final JList list,
        @NonNull final ButtonModel caseSensitive) {
    Parameters.notNull("list", list);   //NOI18N
    Parameters.notNull("caseSensitive", caseSensitive); //NOI18N
    return ItemRenderer.Builder.create(
        list,
        caseSensitive,
        new SymbolDescriptorCovertor()).build();
}
项目:incubator-netbeans    文件:GoToTypeAction.java   
@Override
public ListCellRenderer getListCellRenderer(
        @NonNull final JList list,
        @NonNull final ButtonModel caseSensitive) {
    Parameters.notNull("list", list);   //NOI18N
    Parameters.notNull("caseSensitive", caseSensitive); //NOI18N
    return ItemRenderer.Builder.create(
            list,
            caseSensitive,
            new TypeDescriptorConvertor()).build();
}
项目:incubator-netbeans    文件:J2EEUtils.java   
public static ListCellRenderer getRenderer() {
    return new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (value instanceof DBColumnInfo) {
                DBColumnInfo column = (DBColumnInfo)value;
                String label = column.getName() + (column.isValid() ? "" : " (" + column.getMessage() + ")"); // NOI18N
                setText(label);
                setEnabled(column.isValid());
            }
            return this;
        }
    };
}
项目:rapidminer    文件:ComboBoxUI.java   
@Override
public void paintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus) {
    ListCellRenderer renderer = this.comboBox.getRenderer();
    Component c;

    if (hasFocus && !isPopupVisible(this.comboBox)) {
        c = renderer.getListCellRendererComponent(this.listBox, this.comboBox.getSelectedItem(), -1, true, false);
    } else {
        c = renderer.getListCellRendererComponent(this.listBox, this.comboBox.getSelectedItem(), -1, false, false);
        c.setBackground(UIManager.getColor("ComboBox.background"));
    }
    c.setFont(this.comboBox.getFont());

    if (this.comboBox.isEnabled()) {
        c.setForeground(this.comboBox.getForeground());
        c.setBackground(this.comboBox.getBackground());
    } else {
        c.setForeground(UIManager.getColor("ComboBox.disabledForeground"));
        c.setBackground(UIManager.getColor("ComboBox.disabledBackground"));
    }

    boolean shouldValidate = false;
    if (c instanceof JPanel) {
        shouldValidate = true;
    }

    if (Boolean.parseBoolean(String.valueOf(comboBox.getClientProperty(RapidLookTools.PROPERTY_INPUT_BACKGROUND_DARK)))) {
        c.setBackground(Colors.COMBOBOX_BACKGROUND_DARK);
    } else {
        c.setBackground(Colors.COMBOBOX_BACKGROUND);
    }

    this.currentValuePane.paintComponent(g, c, this.comboBox, bounds.x, bounds.y, bounds.width, bounds.height,
            shouldValidate);
}
项目:SER316-Dresden    文件:NotesList.java   
public ListCellRenderer getCellRenderer() {
       return new DefaultListCellRenderer()  {

    public Component getListCellRendererComponent(
      JList list,
      Object value,            // value to display
      int index,               // cell index
      boolean isSelected,      // is the cell selected
      boolean cellHasFocus)    // the list and the cell have the focus
    {
        JLabel label = (JLabel)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        String s = value.toString();
        label.setText(s);
        //Note currentNote = CurrentProject.getNoteList().getActiveNote();
        Note currentNote = CurrentNote.get();
        if (currentNote != null) {
           if (getNote(index).getId().equals(currentNote.getId()))
               label.setFont(label.getFont().deriveFont(Font.BOLD));
        }
        if (getNote(index).isMarked())
           label.setIcon(IconFontSwing.buildIcon(GoogleMaterialDesignIcons.STAR, 8, ColorMap.ICON));
        //setIcon();
      /*if (isSelected) {
            setBackground(list.getSelectionBackground());
          setForeground(list.getSelectionForeground());
      }
        else {
          setBackground(list.getBackground());
          setForeground(list.getForeground());
      }
      setEnabled(list.isEnabled());
      setFont(list.getFont());
        setOpaque(true);*/
        label.setToolTipText(s);
        return label;
    }
   };

}
项目:gate-core    文件:ResourceParametersEditor.java   
public ParameterDisjunctionRenderer() {
  combo = new JComboBox();
  class CustomRenderer extends JLabel implements ListCellRenderer {
    @Override
    public Component getListCellRendererComponent(JList list, Object value,
            int index, boolean isSelected, boolean cellHasFocus) {

      setText(text);
      setIcon(icon);
      return this;
    }
  }
  combo.setRenderer(new CustomRenderer());
}
项目:zencash-swing-wallet-ui    文件:JContactListPanel.java   
@Override
public ListCellRenderer<MessagingIdentity> getCellRenderer() 
{
    return new ListCellRenderer<MessagingIdentity>() 
    {
        @Override
        public Component getListCellRendererComponent(JList<? extends MessagingIdentity> list,
                MessagingIdentity id, int index, boolean isSelected, boolean cellHasFocus) 
        {                   
            renderer.setText(id.getDiplayString());
            if (!id.isGroup())
            {
                renderer.setIcon(contactBlackIcon);
            } else
            {
                renderer.setIcon(contactGroupBlackIcon);
            }

            if (isSelected) 
            {
                renderer.setBackground(list.getSelectionBackground());
            } else 
            {
                // TODO: list background issues on Linux - if used directly
                renderer.setBackground(new Color(list.getBackground().getRGB()));  
            }

            return renderer;
        }
    };
}
项目:freecol    文件:BuildQueuePanel.java   
/**
 * Set the correct cell renderer in the buildables lists.
 */
private void updateDetailView() {
    ListCellRenderer<BuildableType> cellRenderer
        = (this.compactBox.isSelected())
        ? new FreeColComboBoxRenderer<BuildableType>()
        : new DefaultBuildQueueCellRenderer();
    this.buildQueueList.setCellRenderer(cellRenderer);
    this.buildingList.setCellRenderer(cellRenderer);
    this.unitList.setCellRenderer(cellRenderer);
}
项目:SER316-Munich    文件:NotesList.java   
public ListCellRenderer getCellRenderer() {
       return new DefaultListCellRenderer()  {

    public Component getListCellRendererComponent(
      JList list,
      Object value,            // value to display
      int index,               // cell index
      boolean isSelected,      // is the cell selected
      boolean cellHasFocus)    // the list and the cell have the focus
    {
        JLabel label = (JLabel)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        String s = value.toString();
        label.setText(s);
        //Note currentNote = CurrentProject.getNoteList().getActiveNote();
     Note currentNote = CurrentNote.get();
        if (currentNote != null) {
           if (getNote(index).getId().equals(currentNote.getId()))
               label.setFont(label.getFont().deriveFont(Font.BOLD));
        }
        if (getNote(index).isMarked())
           label.setIcon(bookmarkIcon);
        //setIcon();
      /*if (isSelected) {
            setBackground(list.getSelectionBackground());
          setForeground(list.getSelectionForeground());
      }
        else {
          setBackground(list.getBackground());
          setForeground(list.getForeground());
      }
      setEnabled(list.isEnabled());
      setFont(list.getFont());
        setOpaque(true);*/
        label.setToolTipText(s);
        return label;
    }
   };

}
项目:SER316-Ingolstadt    文件:NotesList.java   
public ListCellRenderer getCellRenderer() {
       return new DefaultListCellRenderer()  {

    public Component getListCellRendererComponent(
      JList list,
      Object value,            // value to display
      int index,               // cell index
      boolean isSelected,      // is the cell selected
      boolean cellHasFocus)    // the list and the cell have the focus
    {
        JLabel label = (JLabel)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        String s = value.toString();
        label.setText(s);
        //Note currentNote = CurrentProject.getNoteList().getActiveNote();
     Note currentNote = CurrentNote.get();
        if (currentNote != null) {
           if (getNote(index).getId().equals(currentNote.getId()))
               label.setFont(label.getFont().deriveFont(Font.BOLD));
        }
        if (getNote(index).isMarked())
           label.setIcon(bookmarkIcon);
        //setIcon();
      /*if (isSelected) {
            setBackground(list.getSelectionBackground());
          setForeground(list.getSelectionForeground());
      }
        else {
          setBackground(list.getBackground());
          setForeground(list.getForeground());
      }
      setEnabled(list.isEnabled());
      setFont(list.getFont());
        setOpaque(true);*/
        label.setToolTipText(s);
        return label;
    }
   };

}
项目:Wilmersdorf_SER316    文件:NotesList.java   
public ListCellRenderer getCellRenderer() {
       return new DefaultListCellRenderer()  {

    public Component getListCellRendererComponent(
      JList list,
      Object value,            // value to display
      int index,               // cell index
      boolean isSelected,      // is the cell selected
      boolean cellHasFocus)    // the list and the cell have the focus
    {
        JLabel label = (JLabel)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        String s = value.toString();
        label.setText(s);
        //Note currentNote = CurrentProject.getNoteList().getActiveNote();
     Note currentNote = CurrentNote.get();
        if (currentNote != null) {
           if (getNote(index).getId().equals(currentNote.getId()))
               label.setFont(label.getFont().deriveFont(Font.BOLD));
        }
        if (getNote(index).isMarked())
           label.setIcon(bookmarkIcon);
        //setIcon();
      /*if (isSelected) {
            setBackground(list.getSelectionBackground());
          setForeground(list.getSelectionForeground());
      }
        else {
          setBackground(list.getBackground());
          setForeground(list.getForeground());
      }
      setEnabled(list.isEnabled());
      setFont(list.getFont());
        setOpaque(true);*/
        label.setToolTipText(s);
        return label;
    }
   };

}
项目:jdk8u-jdk    文件:Test7195179.java   
public static void main(String[] args) throws Exception {
    invokeAndWait(new Runnable() {
        @Override
        public void run() {
            Integer[] items = {null, 1, 2, 3};
            JComboBox<Integer> combo = new JComboBox<>(items);
            JLabel label = new JLabel("choose:");
            JPanel panel = new JPanel();
            GroupLayout layout = new GroupLayout(panel);
            panel.setLayout(layout);
            label.setLabelFor(combo);
            combo.setSelectedIndex(0);
            combo.setRenderer(new ListCellRenderer<Integer>() {
                private final BasicComboBoxRenderer renderer = new BasicComboBoxRenderer();

                @Override
                public Component getListCellRendererComponent(JList<? extends Integer> list, Integer value, int index, boolean isSelected, boolean cellHasFocus) {
                    return this.renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                }
            });
            layout.setAutoCreateContainerGaps(true);
            layout.setAutoCreateGaps(true);
            layout.setHorizontalGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup().addComponent(label))
                    .addGroup(layout.createParallelGroup().addComponent(combo)));
            layout.setVerticalGroup(layout
                    .createSequentialGroup()
                    .addGroup(layout
                            .createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(label)
                            .addComponent(combo)));

            JFrame frame = new JFrame(getClass().getSimpleName());
            frame.add(panel);
            frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            frame.pack();
            frame.setVisible(true);
        }
    });
}
项目:openjdk-jdk10    文件:Test7195179.java   
public static void main(String[] args) throws Exception {
    invokeAndWait(new Runnable() {
        @Override
        public void run() {
            Integer[] items = {null, 1, 2, 3};
            JComboBox<Integer> combo = new JComboBox<>(items);
            JLabel label = new JLabel("choose:");
            JPanel panel = new JPanel();
            GroupLayout layout = new GroupLayout(panel);
            panel.setLayout(layout);
            label.setLabelFor(combo);
            combo.setSelectedIndex(0);
            combo.setRenderer(new ListCellRenderer<Integer>() {
                private final BasicComboBoxRenderer renderer = new BasicComboBoxRenderer();

                @Override
                public Component getListCellRendererComponent(JList<? extends Integer> list, Integer value, int index, boolean isSelected, boolean cellHasFocus) {
                    return this.renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                }
            });
            layout.setAutoCreateContainerGaps(true);
            layout.setAutoCreateGaps(true);
            layout.setHorizontalGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup().addComponent(label))
                    .addGroup(layout.createParallelGroup().addComponent(combo)));
            layout.setVerticalGroup(layout
                    .createSequentialGroup()
                    .addGroup(layout
                            .createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(label)
                            .addComponent(combo)));

            JFrame frame = new JFrame(getClass().getSimpleName());
            frame.add(panel);
            frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            frame.pack();
            frame.setVisible(true);
        }
    });
}
项目:openjdk-jdk10    文件:JComboBoxOperator.java   
/**
 * Maps {@code JComboBox.getRenderer()} through queue
 */
public ListCellRenderer<?> getRenderer() {
    return (runMapping(new MapAction<ListCellRenderer<?>>("getRenderer") {
        @Override
        public ListCellRenderer<?> map() {
            return ((JComboBox) getSource()).getRenderer();
        }
    }));
}
项目:openjdk-jdk10    文件:JComboBoxOperator.java   
/**
 * Maps {@code JComboBox.setRenderer(ListCellRenderer)} through queue
 */
@SuppressWarnings(value = "unchecked")
public void setRenderer(final ListCellRenderer<?> listCellRenderer) {
    runMapping(new MapVoidAction("setRenderer") {
        @Override
        public void map() {
            ((JComboBox) getSource()).setRenderer(listCellRenderer);
        }
    });
}
项目:openjdk-jdk10    文件:JListOperator.java   
/**
 * Ask renderer for component to be displayed.
 *
 * @param itemIndex Item index.
 * @param isSelected True if the specified cell was selected.
 * @param cellHasFocus True if the specified cell has the focus.
 * @return Component to be displayed.
 */
@SuppressWarnings(value = "unchecked")
public Component getRenderedComponent(int itemIndex, boolean isSelected, boolean cellHasFocus) {
    return (((ListCellRenderer<Object>) getCellRenderer()).
            getListCellRendererComponent((JList<Object>) getSource(),
                    getModel().getElementAt(itemIndex),
                    itemIndex,
                    isSelected,
                    cellHasFocus));
}
项目:openjdk-jdk10    文件:JListOperator.java   
/**
 * Maps {@code JList.getCellRenderer()} through queue
 */
public ListCellRenderer<?> getCellRenderer() {
    return (runMapping(new MapAction<ListCellRenderer<?>>("getCellRenderer") {
        @Override
        public ListCellRenderer<?> map() {
            return ((JList) getSource()).getCellRenderer();
        }
    }));
}
项目:Reinickendorf_SER316    文件:NotesList.java   
public ListCellRenderer getCellRenderer() {
       return new DefaultListCellRenderer()  {

    public Component getListCellRendererComponent(
      JList list,
      Object value,            // value to display
      int index,               // cell index
      boolean isSelected,      // is the cell selected
      boolean cellHasFocus)    // the list and the cell have the focus
    {
        JLabel label = (JLabel)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        String s = value.toString();
        label.setText(s);
        //Note currentNote = CurrentProject.getNoteList().getActiveNote();
     Note currentNote = CurrentNote.get();
        if (currentNote != null) {
           if (getNote(index).getId().equals(currentNote.getId()))
               label.setFont(label.getFont().deriveFont(Font.BOLD));
        }
        if (getNote(index).isMarked())
           label.setIcon(bookmarkIcon);
        //setIcon();
      /*if (isSelected) {
            setBackground(list.getSelectionBackground());
          setForeground(list.getSelectionForeground());
      }
        else {
          setBackground(list.getBackground());
          setForeground(list.getForeground());
      }
      setEnabled(list.isEnabled());
      setFont(list.getFont());
        setOpaque(true);*/
        label.setToolTipText(s);
        return label;
    }
   };

}
项目:FreeCol    文件:BuildQueuePanel.java   
/**
 * Set the correct cell renderer in the buildables lists.
 */
private void updateDetailView() {
    ListCellRenderer<BuildableType> cellRenderer
        = (this.compactBox.isSelected())
        ? new FreeColComboBoxRenderer<BuildableType>()
        : new DefaultBuildQueueCellRenderer();
    this.buildQueueList.setCellRenderer(cellRenderer);
    this.buildingList.setCellRenderer(cellRenderer);
    this.unitList.setCellRenderer(cellRenderer);
}
项目:Dahlem_SER316    文件:NotesList.java   
public ListCellRenderer getCellRenderer() {
       return new DefaultListCellRenderer()  {

    public Component getListCellRendererComponent(
      JList list,
      Object value,            // value to display
      int index,               // cell index
      boolean isSelected,      // is the cell selected
      boolean cellHasFocus)    // the list and the cell have the focus
    {
        JLabel label = (JLabel)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);

        //Possible future use, allows user to click on star to add bookmark 
        //Not fully functional.
        /*list.addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent e) {
                 Point p = e.getPoint();
                 int pointIndex = list.locationToIndex(p);
                 Note currentNote = getNote(pointIndex);
                 //NotesControlPanel ncp = new NotesControlPanel();

                 if(p.getX() < 10){
                     if(currentNote.isMarked()){
                         currentNote.setMark(false);
                         //ncp.ppRemoveBkmrk_actionPerformed(currentNote);
                         //list.updateUI();
                         list.repaint();
                      }
                      else{
                          currentNote.setMark(true);
                          //ncp.ppAddBkmrk_actionPerformed(currentNote);
                          //list.updateUI();
                          list.repaint();
                      }
                 }
            }
        });*/

        String s = value.toString();
        label.setText(s);
        //Note currentNote = CurrentProject.getNoteList().getActiveNote();
     Note currentNote = CurrentNote.get();
        if (currentNote != null) {
           if (getNote(index).getId().equals(currentNote.getId()))
               label.setFont(label.getFont().deriveFont(Font.BOLD));
        }
        if (getNote(index).isMarked()){
            label.setIcon(bookmarkIcon);
         }
         else{
         //All new notes will be initialized with an empty star.
             label.setIcon(emptyStar);
         }
        //setIcon();
      /*if (isSelected) {
            setBackground(list.getSelectionBackground());
          setForeground(list.getSelectionForeground());
      }
        else {
          setBackground(list.getBackground());
          setForeground(list.getForeground());
      }
      setEnabled(list.isEnabled());
      setFont(list.getFont());
        setOpaque(true);*/
        label.setToolTipText(s);
        return label;
    }
   };

}
项目:incubator-netbeans    文件:JavaFXProjectUtils.java   
public static ListCellRenderer createPlatformListCellRenderer() {
    return PlatformUiSupport.createPlatformListCellRenderer();
}
项目:incubator-netbeans    文件:CustomizerComponentFactory.java   
static ListCellRenderer/*<ModuleDependency|WAIT_VALUE>*/ getDependencyCellRenderer(boolean boldfaceApiModules) {
    return new DependencyListCellRenderer(boldfaceApiModules);
}
项目:incubator-netbeans    文件:CustomizerComponentFactory.java   
static ListCellRenderer/*<ModuleEntry>*/ getModuleEntryCellRenderer() {
    return new ModuleEntryListCellRenderer();
}
项目:incubator-netbeans    文件:JavaPlatformComponentFactory.java   
public static ListCellRenderer/*<JavaPlatform>*/ javaPlatformListCellRenderer() {
    return new Renderer();
}