List of usage examples for javax.swing JList getForeground
@Transient
public Color getForeground()
From source file:Main.java
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean hasFocus) { setEnabled(list.isEnabled());/*from www. ja v a2 s . c o m*/ setSelected(((CheckListItem) value).isSelected()); setFont(list.getFont()); setBackground(list.getBackground()); setForeground(list.getForeground()); setText(value.toString()); return this; }
From source file:Main.java
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { setText(value.toString());// www.j a va 2 s . c om 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; }
From source file:MyCellRenderer.java
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { setText(value.toString());/*from ww w.j av a 2s . c o m*/ if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else { setBackground(list.getBackground()); setForeground(list.getForeground()); } return this; }
From source file:net.sf.maltcms.chromaui.charts.renderer.XYPlotRendererListCellRenderer.java
@Override public Component getListCellRendererComponent(JList list, Object value, int i, boolean isSelected, boolean hasFocus) { //Get the selected index. (The index param isn't //always valid, so just use the value.) // int selectedIndex = ((Integer)value).intValue(); if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else {/*from w ww . j a v a 2s . com*/ setBackground(list.getBackground()); setForeground(list.getForeground()); } if (value instanceof XYItemRenderer) { String className = ((XYItemRenderer) value).getClass().getSimpleName(); className = className.replaceFirst("XY", ""); className = className.replaceFirst("Renderer", ""); setText(className); } return this; }
From source file:ie.philb.testorderingsoapclient.ui.nav.products.ProductListCellRenderer.java
@Override public Component getListCellRendererComponent(JList<? extends Product> list, Product value, int index, boolean isSelected, boolean cellHasFocus) { if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else {//from w w w .ja v a 2 s . c om if ((index % 2) == 0) { //setBackground(list.getBackground()); setBackground(new java.awt.Color(255, 255, 255)); setForeground(list.getForeground()); } else { setBackground(new java.awt.Color(245, 245, 245)); } } ListModel lm = list.getModel(); if (lm instanceof ProductListModel) { ProductListModel plm = (ProductListModel) lm; if (index < plm.getSize()) { Product p = plm.getElementAt(index); Money unitPrice = p.getUnitPrice(); lblTitle.setText(WordUtils.capitalize(p.getTitle())); lblCode.setText(p.getSkuCode()); lblUnitPrice.setText("" + unitPrice.getValue().toPlainString()); } else { lblTitle.setText(""); } return this; } return (Component) list.getCellRenderer(); }
From source file:MainClass.java
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Font theFont = null;/*from w ww . j a va2s .c o m*/ Color theForeground = null; String theText = null; JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (value instanceof Object[]) { Object values[] = (Object[]) value; theFont = (Font) values[0]; theForeground = (Color) values[1]; theText = (String) values[2]; } else { theFont = list.getFont(); theForeground = list.getForeground(); theText = ""; } if (!isSelected) { renderer.setForeground(theForeground); } renderer.setText(theText); renderer.setFont(theFont); return renderer; }
From source file:Main.java
public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) { return new JPanel() { public void paintComponent(Graphics g) { super.paintComponent(g); Font font = (Font) value; String text = font.getFamily(); FontMetrics fm = g.getFontMetrics(font); g.setColor(isSelected ? list.getSelectionBackground() : list.getBackground()); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(isSelected ? list.getSelectionForeground() : list.getForeground()); g.setFont(font);/*from ww w. java2s .c o m*/ g.drawString(text, 0, fm.getAscent()); } public Dimension getPreferredSize() { Font font = (Font) value; String text = font.getFamily(); Graphics g = getGraphics(); FontMetrics fm = g.getFontMetrics(font); return new Dimension(fm.stringWidth(text), fm.getHeight()); } }; }
From source file:ComplexCellRenderer.java
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Font theFont = null;/*from w w w . j av a2s . c o m*/ Color theForeground = null; Icon theIcon = null; String theText = null; JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (value instanceof Object[]) { Object values[] = (Object[]) value; theFont = (Font) values[0]; theForeground = (Color) values[1]; theIcon = (Icon) values[2]; theText = (String) values[3]; } else { theFont = list.getFont(); theForeground = list.getForeground(); theText = ""; } if (!isSelected) { renderer.setForeground(theForeground); } if (theIcon != null) { renderer.setIcon(theIcon); } renderer.setText(theText); renderer.setFont(theFont); return renderer; }
From source file:CheckBoxList.java
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (value instanceof CheckBoxListEntry) { CheckBoxListEntry checkbox = (CheckBoxListEntry) value; checkbox.setBackground(isSelected ? list.getSelectionBackground() : list.getBackground()); if (checkbox.isRed()) { checkbox.setForeground(Color.red); } else {//from ww w . j a v a 2s . c o m checkbox.setForeground(isSelected ? list.getSelectionForeground() : list.getForeground()); } checkbox.setEnabled(isEnabled()); checkbox.setFont(getFont()); checkbox.setFocusPainted(false); checkbox.setBorderPainted(true); checkbox.setBorder(isSelected ? UIManager.getBorder("List.focusCellHighlightBorder") : noFocusBorder); return checkbox; } else { return super.getListCellRendererComponent(list, value.getClass().getName(), index, isSelected, cellHasFocus); } }
From source file:gg.msn.ui.panel.MainPanel.java
@Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { this.value = value; this.list = list; /*se il valore non nullo impossto il renderig altrimenti lo lascio nascosto, questo impedisce che lo spazio bianco selweziona sempre l'utlimo elemento*/ // log.debug("Render lement : " + value); if (isSelected) { setOpaque(true);//from www . j a v a2 s .c o m setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else { setOpaque(false); setBackground(list.getBackground()); setForeground(list.getForeground()); } // <editor-fold defaultstate="collapsed" desc="Old Code"> /* try { //render per utenti Facebook if (ChatClientView.protocol.equals(ChatClientView.FACEBOOK_PROTOCOL)) { final FacebookUser user = (FacebookUser) value; setText(user.name); ImageIcon icon = user.portrait; //log.debug("icon [" + icon + "]"); ImageIcon scaledIcon = new ImageIcon(icon.getImage().getScaledInstance(24, 24, Image.SCALE_AREA_AVERAGING)); setFont(list.getFont()); setIcon(scaledIcon); //render per utenti Client } else { Client client = (Client) value; setText((client).getNick()); ImageIcon icon = null; try { new ImageIcon(client.getImage()); } catch (Exception e) { // log.debug("immgine non presente"); icon = ThemeManager.getTheme().get(ThemeManager.USER_ICON); } ImageIcon scaledIcon = new ImageIcon(icon.getImage().getScaledInstance(24, 24, Image.SCALE_AREA_AVERAGING)); setFont(list.getFont()); setIcon(scaledIcon); } } catch (Exception e) { log.warn(e); }*/// </editor-fold> return this; }