public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Object[] values = (Object[]) list.getModel().getElementAt(index); String icoState = (String) (values[0]); setIcon(null); if (icoState.equals("bad")) { // Error setIcon(errIco); setBackground(list.getSelectionForeground()); // RED setForeground(Color.BLACK); setBorder(BorderFactory.createLineBorder(Color.BLUE, 1)); } else if (icoState.equals("good")) { // Ok setIcon(nrmIco); setBackground(list.getSelectionBackground()); // GREEN setForeground(Color.BLACK); setBorder(BorderFactory.createLineBorder(Color.BLUE, 1)); } else if (icoState.equals("goodcont")) { // Ok setIcon(imdIco); setBackground(list.getSelectionBackground()); // GREEN setForeground(Color.BLACK); setBorder(BorderFactory.createLineBorder(list.getSelectionBackground(), 1)); } else { setIcon(ibdIco); // Errorcont setBackground(list.getSelectionForeground()); // RED setForeground(Color.BLACK); setBorder(BorderFactory.createLineBorder(list.getSelectionForeground(), 1)); } setText((String) (values[1])); setFont(list.getFont()); return this; }
public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { // #93658: GTK needs name to render cell renderer "natively" setName("ComboBox.listRenderer"); // NOI18N String config = (String) value; String label; if (config == null) { // uninitialized? label = null; } else if (config.length() > 0) { Map<String, String> m = configs.get(config); label = m != null ? m.get("$label") : /* temporary? */ null; // NOI18N if (label == null) { label = config; } } else { label = NbBundle.getBundle("org.netbeans.modules.java.j2seproject.Bundle") .getString("J2SEConfigurationProvider.default.label"); // NOI18N } setText(label); if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else { setBackground(list.getBackground()); setForeground(list.getForeground()); } return this; }
public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { /** * if (isSelected) { setBackground(UIManager.getColor("ComboBox.selectionBackground")); * setForeground(UIManager.getColor("ComboBox.selectionForeground")); } else { * setBackground(UIManager.getColor("ComboBox.background")); * setForeground(UIManager.getColor("ComboBox.foreground")); }* */ if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else { setBackground(list.getBackground()); setForeground(list.getForeground()); } setFont(list.getFont()); if (value instanceof Icon) { setIcon((Icon) value); } else { setText((value == null) ? "" : value.toString()); } return this; }
@Override public Component getListCellRendererComponent( JList<? extends E> list, E value, int index, boolean isSelected, boolean cellHasFocus) { label.setText(Objects.toString(value, "")); this.list = list; this.index = index; if (isSelected) { setBackground(list.getSelectionBackground()); label.setForeground(list.getSelectionForeground()); } else { setBackground(index % 2 == 0 ? EVEN_COLOR : list.getBackground()); label.setForeground(list.getForeground()); } MutableComboBoxModel m = (MutableComboBoxModel) list.getModel(); if (index < 0 || m.getSize() - 1 <= 0) { setOpaque(false); deleteButton.setVisible(false); label.setForeground(list.getForeground()); } else { boolean f = index == rolloverIndex; setOpaque(true); deleteButton.setVisible(true); deleteButton.getModel().setRollover(f); deleteButton.setForeground(f ? Color.WHITE : list.getForeground()); } return this; }
public Component getListCellRendererComponent( JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { // Method Instances. String buttonTextLabel; Color buttonColor; Font buttonFont; // Set label, background, selection highlight, & font. buttonTextLabel = ((SQLQueryBucketListObject) value).getText(); buttonColor = ((SQLQueryBucketListObject) value).getBackground(); buttonFont = list.getFont(); setText(buttonTextLabel); setBackground(buttonColor); if (isSelected) { setBorder(BorderFactory.createLineBorder(list.getSelectionForeground(), 1)); } else { setBorder(((SQLQueryBucketListObject) value).getBorder()); } setEnabled(list.isEnabled()); setFont(buttonFont.deriveFont(Font.BOLD)); setOpaque(true); return this; }
protected void paintComponent(Graphics g) { // Set up rendering hints to look as close to native as possible Graphics2D g2d = (Graphics2D) g; Object old = null; // First, try to use the rendering hint set that is "native". Map hints = (Map) getToolkit().getDesktopProperty("awt.font.desktophints"); if (hints != null) { old = g2d.getRenderingHints(); g2d.addRenderingHints(hints); } // If a "native" set isn't found, just turn on standard text AA. else { old = g2d.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING); g2d.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } // if (jsc!=null) { // setText(null); // Stop "Foobar" from being painted // } // We never paint "selection" around the icon, to imitate Eclipse final int iconW = 18; int h = getHeight(); if (!selected) { g.setColor(getBackground()); g.fillRect(0, 0, getWidth(), h); } else { g.setColor(altBG != null && evenRow ? altBG : list.getBackground()); g.fillRect(0, 0, iconW, h); g.setColor(getBackground()); // Selection color g.fillRect(iconW, 0, getWidth() - iconW, h); } if (getIcon() != null) { int y = (h - getIcon().getIconHeight()) / 2; getIcon().paintIcon(this, g, 0, y); } int x = getX() + iconW + 2; g.setColor(selected ? list.getSelectionForeground() : list.getForeground()); if (jsc != null && !simpleText) { jsc.rendererText(g, x, g.getFontMetrics().getHeight(), selected); } else { Completion c = jsc != null ? (Completion) jsc : nonJavaCompletion; if (c != null) { g.drawString(c.toString(), x, g.getFontMetrics().getHeight()); } } // Restore rendering hints appropriately. if (hints != null) { g2d.addRenderingHints((Map) old); } else { g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, old); } }
@Override protected void fillPage( final Page page, JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Color foreground = isSelected ? list.getSelectionForeground() : list.getForeground(); Color background = isSelected ? list.getSelectionBackground() : list.getBackground(); renderCellValue(page, value, foreground, background, isSelected); }
public Renderer(JList list) { setFont(list.getFont()); fgColor = list.getForeground(); bgColor = list.getBackground(); bgColorDarker = new Color( Math.abs(bgColor.getRed() - DARKER_COLOR_COMPONENT), Math.abs(bgColor.getGreen() - DARKER_COLOR_COMPONENT), Math.abs(bgColor.getBlue() - DARKER_COLOR_COMPONENT)); bgSelectionColor = list.getSelectionBackground(); fgSelectionColor = list.getSelectionForeground(); }
@SuppressWarnings("rawtypes") @Override public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (value != null) { FBUser user = (FBUser) value; setText(user.getName()); } setBackground(isSelected ? list.getSelectionBackground() : list.getBackground()); setForeground(isSelected ? list.getSelectionForeground() : list.getForeground()); return this; }
public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { setText(value.toString()); setBackground(isSelected ? list.getSelectionBackground() : list.getBackground()); setForeground(isSelected ? list.getSelectionForeground() : list.getForeground()); setFont(list.getFont()); setBorder( (cellHasFocus) ? UIManager.getBorder("List.focusCellHighlightBorder") : m_noFocusBorder); return this; }
/* * This method finds the image and text corresponding * to the selected value and returns the label, set up * to display the text and image. */ @Override public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else { setBackground(list.getBackground()); setForeground(list.getForeground()); } return this; }
public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else { setBackground(list.getBackground()); setForeground(list.getForeground()); } ImageIcon icon = (ImageIcon) value; setText(icon.getDescription()); setIcon(icon); return this; }
/** * Return a component that has been configured to display the specified value. * * @param list The JList we're painting. * @param value The value returned by list.getModel().getElementAt(index). * @param index The cells index. * @param isSelected True if the specified cell was selected. * @param cellHasFocus True if the specified cell has the focus. * @return A component whose paint() method will render the specified value. * @todo Implement this javax.swing.ListCellRenderer method */ public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { HostItem hi = (HostItem) value; JLabel c = new JLabel(hi.name); if (isSelected && hi.eavesDroppingEnabled) { c.setBackground(Color.magenta); c.setForeground(list.getSelectionForeground()); } else if (!isSelected && hi.eavesDroppingEnabled) { c.setBackground(Color.red); c.setForeground(list.getForeground()); } else if (isSelected) { c.setBackground(list.getSelectionBackground()); c.setForeground(list.getSelectionForeground()); } else { c.setBackground(list.getBackground()); c.setForeground(list.getForeground()); } c.setEnabled(list.isEnabled()); c.setFont(list.getFont()); c.setOpaque(true); return c; }
public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean hasFocus) { setEnabled(list.isEnabled()); setSelected(((CheckListItem) value).isSelected()); setFont(list.getFont()); if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else { setBackground(list.getBackground()); setForeground(list.getForeground()); } setText(value.toString()); return this; }
@Override public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { String key = (String) value; if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else { setBackground(list.getBackground()); setForeground(list.getForeground()); } setText(key); setIcon(content.get(key)); setFont(list.getFont()); return this; }
/* * This method finds the image and text corresponding * to the selected value and returns the label, set up * to display the text and image. */ public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { // Get the selected index. (The index param isn't // always valid, so just use the value.) if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); // setBorder(BorderFactory.createLineBorder(Color.red,2)); } else { setBackground(list.getBackground()); setForeground(list.getForeground()); } setHorizontalAlignment(LEFT); setText(((App) value).getNombre()); return this; }
public Component getListCellRendererComponent( JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (value != null) { Integer num = (Integer) value; setText(cm.NameMap.get(num)); setIcon(new ImageIcon(cm.IconMap.get(num))); } if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else { // 设置选取与取消选取的前景与背景颜色. setBackground(list.getBackground()); setForeground(list.getForeground()); } return this; }
/** * Gets the list cell renderer component. * * @param list the instance of JList * @param value the value object * @param index the index value * @param isSelected the boolean of isSelected * @param cellHasFocus the boolean of cellHasFocus */ public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean hasFocus) { IElementNode elementNode = (IElementNode) value; checkBox.setSelected(elementNode.isSelected()); cellLabel.setText(elementNode.getText()); cellLabel.setIcon(elementNode.getIcon()); cellLabel.setToolTipText(elementNode.getToolTipText()); cellLabel.setSelected(isSelected); cellLabel.setFont(list.getFont()); cellLabel.setFocus(hasFocus); cellLabel.setBackground(isSelected ? list.getSelectionBackground() : list.getBackground()); cellLabel.setForeground(isSelected ? list.getSelectionForeground() : list.getForeground()); setToolTipText(elementNode.getToolTipText()); return this; }
@Override public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { XmlElementDescriptor descriptor = (XmlElementDescriptor) value; Color backgroundColor = isSelected ? list.getSelectionBackground() : list.getBackground(); myNameLabel.setText(descriptor.getName()); myNameLabel.setForeground(isSelected ? list.getSelectionForeground() : list.getForeground()); myPanel.setBackground(backgroundColor); myNSLabel.setText(getNamespace(descriptor)); myNSLabel.setForeground(LookupCellRenderer.getGrayedForeground(isSelected)); myNSLabel.setBackground(backgroundColor); return myPanel; }
public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Testable testCase = (Testable) value; setText(testName(testCase)); setOpaque(true); setIcon(testCase.isPassed() ? tickIcon : (testCase.isFailed() ? crossIcon : clearIcon)); if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else { setBackground(list.getBackground()); setForeground(list.getForeground()); } setEnabled(list.isEnabled()); setFont(list.getFont()); return this; }
public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { String s = value.toString(); setText(s); if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else { setBackground(list.getBackground()); setForeground(list.getForeground()); } setEnabled(list.isEnabled()); setFont(list.getFont()); setOpaque(true); setToolTipText(((StyleSourceInfo) value).getTooltip()); return this; }
public Component getListCellRendererComponent( JList<? extends String> list, String value, int index, boolean isSelected, boolean cellHasFocus) { setIcon(getIcon(value, parser)); if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else { setBackground(list.getBackground()); setForeground(list.getForeground()); } setEnabled(list.isEnabled()); return this; }
@Override public Component getListCellRendererComponent( JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { final MagicDeck deck = (MagicDeck) value; final Component c = super.getListCellRendererComponent(list, deck.getName(), index, isSelected, cellHasFocus); if (deck.isValid() == false) { if (invalidDeckFont == null) { final Map<TextAttribute, Object> attributes = new HashMap<>(); attributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON); invalidDeckFont = c.getFont().deriveFont(attributes); } c.setFont(invalidDeckFont); c.setForeground(isSelected ? list.getSelectionForeground() : Color.RED.darker()); } return c; }
/** {@inheritDoc} */ @Override public Component getListCellRendererComponent( JList<? extends String> list, String value, int index, boolean isSelected, boolean cellHasFocus) { FreeColGameObject fcgo = getGame().getFreeColGameObject(value); if (fcgo instanceof Location) { setText(Messages.message(((Location) fcgo).getLocationLabel())); } else { setText(value); } setForeground((isSelected) ? list.getSelectionForeground() : list.getForeground()); setBackground((isSelected) ? list.getSelectionBackground() : list.getBackground()); return this; }
public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (value != null) { panel.setTodoItem((TodoItem) value); } if (isSelected) { adjustColors(list.getSelectionBackground(), list.getSelectionForeground()); } else { adjustColors(list.getBackground(), list.getForeground()); if ((index % 2) == 0) { panel.setBackground(STRIPE_COLOR); adjustColors(STRIPE_COLOR, list.getForeground()); } } return panel; }
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { setText(" " + ((JmolInstance) value).name); if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else { setBackground(list.getBackground()); setForeground(list.getForeground()); } setEnabled(list.isEnabled()); setFont(list.getFont()); setOpaque(true); enableButtons(list); return this; }
@Override public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { String str = (value == null) ? null : value.toString(); if (Utils.SEPARATOR.equals(str)) { return separator; } if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else { setBackground(list.getBackground()); setForeground(list.getForeground()); } setFont(list.getFont()); setText(str); updateHeight(); return this; }
@Override public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { // int selectedIndex = ((Integer)value).intValue(); if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else { setBackground(list.getBackground()); setForeground(list.getForeground()); } if (value != null) { setIcon((ImageIcon) value); } return this; }
/** * Paint the arrow in the panel, using the current style. * * @param g the graphic context. */ public void paintComponent(Graphics g) { g.setColor(isSelected ? list.getSelectionBackground() : list.getBackground()); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(isSelected ? list.getSelectionForeground() : list.getForeground()); g.drawLine(getWidth() / 3, getHeight() / 2, 2 * getWidth() / 3, getHeight() / 2); Arrow arrowDummy = new Arrow(); arrowDummy.drawArrowPixels( new Graphics2DSwing(g), getWidth() / 3, getHeight() / 2, 2 * getWidth() / 3, getHeight() / 2, 10, 4, arrow.style); }
/** Implement this method in ListCellRenderer */ public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Object[] pair = (Object[]) value; // Cast value into an array jlblCell.setOpaque(true); jlblCell.setIcon((ImageIcon) pair[0]); jlblCell.setText(pair[1].toString()); if (isSelected) { jlblCell.setForeground(list.getSelectionForeground()); jlblCell.setBackground(list.getSelectionBackground()); } else { jlblCell.setForeground(list.getForeground()); jlblCell.setBackground(list.getBackground()); } jlblCell.setBorder(cellHasFocus ? lineBorder : emptyBorder); return jlblCell; }