public Component getListCellRendererComponent( JList list, // the list Object value, // value to display int index, // cell index boolean isSelected, // is the cell selected boolean cellHasFocus) // does the cell have focus { Song song = (Song) value; String display = song.getTitle() + "<br>" + song.getArtist(); setText("<html>" + display); if (isSelected) { setBackground(Const.highlightColor); setForeground(Const.bgColor); } else { setBackground(Const.bgColor); setForeground(Const.txtColor); } // The current playing song if (index == list.getModel().getSize() - 1) { Font f = list.getFont(); setFont(f.deriveFont(Font.BOLD)); } else { setFont(list.getFont()); } setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.LIGHT_GRAY)); setEnabled(list.isEnabled()); setOpaque(true); return this; }
private JScrollPane getClusterList() { if (clustList == null) { clustList = new JList(); clustList.setSelectionBackground(new Color(83, 126, 126)); clustList.setSelectionForeground(Color.BLACK); clustList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); clustList.setFont( new Font( clustList.getFont().getName(), clustList.getFont().getStyle(), clustList.getFont().getSize() + 1)); String[] clustStr = new String[numClusters]; for (int i = 0; i < numClusters; i++) { clustStr[i] = "Cluster " + (i + 1); } clustList.setListData(clustStr); clustList.addListSelectionListener( new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (clustInfo != null && clustList.getSelectedIndex() >= 0) { if (!e.getValueIsAdjusting()) { ((clustTableModel) clustInfo.getModel()) .setData(infos.infoCluster[clustList.getSelectedIndex()].statClust); clustInfo.tableChanged(new TableModelEvent(clustInfo.getModel())); clustDet.setCluster(clustList.getSelectedIndex()); String cur = DESCR_LABEL.replaceFirst( "X", Integer.toString(clustList.getSelectedIndex() + 1)); cur = cur.replaceFirst("Y", Integer.toString(numClusters)); desctText.setText( cur.replaceFirst( "Z", Integer.toString(infos.numElem[clustList.getSelectedIndex()]))); } } } }); } clustList.setSelectedIndex(0); JScrollPane p = new JScrollPane( clustList, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); p.setPreferredSize(new Dimension(120, 115)); return p; }
public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, null, index, isSelected, cellHasFocus); Completion comp = (Completion) value; if (index < 9) setText((index + 1) + ": " + comp.text); else if (index == 9) setText("0: " + comp.text); else setText(comp.text); if (comp.keyword) setFont(list.getFont().deriveFont(Font.BOLD)); else setFont(list.getFont()); return this; }
private void buildLayout(String hostProgramTitle) { DefaultFormBuilder b = new DefaultFormBuilder(new FormLayout("fill:p:grow")); b.append( "<html>The following programs are needed for full functionality of " + hostProgramTitle + ".<br>" + "Install the external program first, then click 'relocate'.<br>" + "If the program is installed but cannot be found, double-click on the program to assign its location manually.</html>"); model = new DefaultListModel(); for (Binary bin : binaries) model.addElement(bin); list = new JList(model); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setFont(list.getFont().deriveFont(Font.PLAIN)); list.setVisibleRowCount(4); list.setCellRenderer( new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel l = (JLabel) super.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus); Binary b = (Binary) value; String found = ""; if (b.isFound()) { l.setIcon(ImageLoader.getImage(ImageLoader.Image.ok)); found = b.getLocation(); } else { l.setIcon(ImageLoader.getImage(ImageLoader.Image.error)); found = "<b>Not found</b>"; } l.setText( "<html><b>" + b.getDescription() + "</b><br><table><tr><td>Program:</td><td>" + b.getCommand() + "</td></tr><tr><td>Location:</td><td>" + found + "</td></tr></html>"); l.setBorder(new EmptyBorder(5, 0, 5, 0)); return l; } }); b.append(new JScrollPane(list)); close = new JButton("Close"); relocate = new JButton("Relocate program automatically."); JPanel buttons = ButtonBarFactory.buildRightAlignedBar(relocate, close); b.append(buttons); b.setBorder(new EmptyBorder(10, 10, 10, 10)); setLayout(new BorderLayout()); add(b.getPanel()); }
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; }
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; }
public ListDialog(JFrame parent, String title, String label, String[] values) { super(parent, title, true, cx, cy, cw, ch, xw, yw, cf); setSize(width, height); container = getContentPane(); container.setLayout(new GridBagLayout()); constraints = new GridBagConstraints(); addWithConstraints(0, new JLabel(label)); display = new JList<String>(values); addWithConstraints(1, new JScrollPane(display)); display.addListSelectionListener(this); selected = new List(); addWithConstraints(2, selected); selected.setFont(display.getFont()); okBouton = new JButton("OK"); addWithConstraints(3, okBouton); okBouton.addActionListener(this); cancelBouton = new JButton("Cancel"); addWithConstraints(4, cancelBouton); cancelBouton.addActionListener(this); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { dispose(); } }); }
public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { assert (value instanceof Node); Node node = (Node) value; String html = "<html><b>" + StringUtils.humanizeName(node.getName()) + "</b> – " + node.getDescription() + "<br><font color=#333333>" + node.getDataClass().getSimpleName() + " —</font> <font color=#666666>" + node.getLibrary().getName() + "</font></html>"; setText(html); if (isSelected) { setBackground(Theme.NODE_SELECTION_ACTIVE_BACKGROUND_COLOR); } else { setBackground(Theme.NODE_SELECTION_BACKGROUND_COLOR); } setEnabled(list.isEnabled()); setFont(list.getFont()); setIcon(new ImageIcon(NodeView.getImageForNode(node))); setBorder(Theme.BOTTOM_BORDER); setOpaque(true); return this; }
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; }
@Override protected void customizeCellRenderer( JList list, Object value, int index, boolean selected, boolean hasFocus) { setIcon(myListEntryIcon); if (myUseIdeaEditor) { int max = list.getModel().getSize(); String indexString = String.valueOf(index + 1); int count = String.valueOf(max).length() - indexString.length(); char[] spaces = new char[count]; Arrays.fill(spaces, ' '); String prefix = indexString + new String(spaces) + " "; append(prefix, SimpleTextAttributes.GRAYED_ATTRIBUTES); } else if (UIUtil.isUnderGTKLookAndFeel()) { // Fix GTK background Color background = selected ? UIUtil.getListSelectionBackground() : UIUtil.getListBackground(); UIUtil.changeBackGround(this, background); } String text = ((Item) value).shortText; FontMetrics metrics = list.getFontMetrics(list.getFont()); int charWidth = metrics.charWidth('m'); int maxLength = list.getParent().getParent().getWidth() * 3 / charWidth / 2; text = StringUtil.first(text, maxLength, true); // do not paint long strings append(text, SimpleTextAttributes.REGULAR_ATTRIBUTES); }
@Override protected void updateItem(JList list, Object value) { if (value instanceof IcyColorMap) { final IcyColorMap colormap = (IcyColorMap) value; final JComboBox comboBox = getComboBox(); final Dimension dim = comboBox.getSize(); int btnWidth; try { // a bit ugly but we really want to access it final JButton popBtn = (JButton) ReflectionUtil.getFieldObject(comboBox.getUI(), "arrowButton", true); btnWidth = popBtn.getWidth(); if (btnWidth <= 0) btnWidth = popBtn.getPreferredSize().width; if (btnWidth <= 0) btnWidth = 20; } catch (Exception e) { btnWidth = 20; } final Insets insets = getInsets(); dim.width -= btnWidth + insets.left + insets.right; dim.height -= insets.top + insets.bottom + 2; setIcon(new ColormapIcon(colormap, dim.width, dim.height)); setText(""); setToolTipText("Set " + colormap.getName() + " colormap"); setEnabled(list.isEnabled()); setFont(list.getFont()); } else super.updateItem(list, value); }
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 { String s = value.toString(); setText(s); setForeground(list.getForeground()); String name = listItems.get(index); if (selected.contains(name)) { if (users.contains(name)) setBackground(Color.GREEN); else setBackground(Color.YELLOW); } else { setBackground(list.getBackground()); } setEnabled(list.isEnabled()); setFont(list.getFont()); setOpaque(true); return this; }
/** * Sets the font level. * * @param level the desired font level */ protected void setFontLevel(int level) { FontSizer.setFonts(this, level); // set cell height of collectionList Font font = collectionList.getFont(); font = FontSizer.getResizedFont(font, level); int space = 8 + level; collectionList.setFixedCellHeight(font.getSize() + space); resizeLabels(); }
public ListRenderer(JList list) { textPanel = new JPanel(); textPanel.add(this); text = new JLabel(); text.setOpaque(true); text.setFont(list.getFont()); textPanel.add(text); }
@Override public Component getListCellRendererComponent( final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) { if (!(value instanceof WrappedLogRecord)) { return new JLabel(); } final WrappedLogRecord wlr = (WrappedLogRecord) value; final JTextPane result = new JTextPane(); result.setDragEnabled(true); result.setText(wlr.formatted); result.setComponentOrientation(list.getComponentOrientation()); result.setFont(list.getFont()); result.setBorder(cellHasFocus || isSelected ? SELECTED_BORDER : EMPTY_BORDER); if (wlr.record.getLevel() == Level.CONFIG) { result.setForeground(DARK_BLUE); } if (wlr.record.getLevel() == Level.SEVERE) { result.setBackground(DARK_RED); result.setForeground(Color.WHITE); } if (wlr.record.getLevel() == Level.WARNING) { result.setForeground(DARK_RED); } if (wlr.record.getLevel() == Level.FINE || wlr.record.getLevel() == Level.FINER || wlr.record.getLevel() == Level.FINEST) { result.setForeground(DARK_GREEN); } final Object[] parameters = wlr.record.getParameters(); if (parameters != null) { for (final Object parameter : parameters) { if (parameter == null) { continue; } if (parameter instanceof Color) { result.setForeground((Color) parameter); } else if (parameter instanceof Font) { result.setFont((Font) parameter); } } } return result; }
public java.awt.Component getListCellRendererComponent( javax.swing.JList list, Object color, int index, boolean isSelected, boolean cellHasFocus) { return getComponent( color, isSelected, list.getBackground(), list.getSelectionBackground(), list.getFixedCellHeight(), list.getFont()); }
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(); }
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; }
private Dimension calcTypeListPreferredSize(final ModuleType[] allModuleTypes) { int width = 0; int height = 0; final FontMetrics fontMetrics = myTypesList.getFontMetrics(myTypesList.getFont()); final int fontHeight = fontMetrics.getMaxAscent() + fontMetrics.getMaxDescent(); for (final ModuleType type : allModuleTypes) { final Icon icon = type.getBigIcon(); final int iconHeight = icon != null ? icon.getIconHeight() : 0; final int iconWidth = icon != null ? icon.getIconWidth() : 0; height += Math.max(iconHeight, fontHeight) + 6; width = Math.max(width, iconWidth + fontMetrics.stringWidth(type.getName()) + 10); } return new Dimension(width, height); }
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; }
/** * Generate a {@link Component} that represents the given object when painted.<br> * <br> * <b>Override this method instead of {@link #getListCellRendererComponent(JList, Object, int, * boolean, boolean)} !</b> * * @param list See {@link #getListCellRendererComponent(JList, Object, int, boolean, boolean)} * @param value See {@link #getListCellRendererComponent(JList, Object, int, boolean, boolean)} * @param index See {@link #getListCellRendererComponent(JList, Object, int, boolean, boolean)} * @param isSelected See {@link #getListCellRendererComponent(JList, Object, int, boolean, * boolean)} * @param cellHasFocus See {@link #getListCellRendererComponent(JList, Object, int, boolean, * boolean)} * @return The {@link Component} that will be painted to represent the given data. */ private Component getObjectComponent( JList list, final Object value, final int index, boolean isSelected, final boolean cellHasFocus) { JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); int padding = list.getFont().getSize() / 2; label.setBorder(BorderFactory.createEmptyBorder(padding, padding, padding, padding)); return label; }
@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; }
/** * 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; }
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 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) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); LibraryPlaylistsListCell cell = (LibraryPlaylistsListCell) value; setText(cell.getText()); setToolTipText(cell.getDescription()); setPreferredSize( new Dimension(getSize().width, TableSettings.DEFAULT_TABLE_ROW_HEIGHT.getValue())); Icon icon = cell.getIcon(); if (icon != null) { setIcon(icon); } this.setFont(list.getFont()); ThemeMediator.fixLabelFont(this); 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; }
private static int getListBaseline(JList list, int height) { int rowHeight = list.getFixedCellHeight(); if (LIST_LABEL == null) { LIST_LABEL = new JLabel("X"); LIST_LABEL.setBorder(new EmptyBorder(1, 1, 1, 1)); } JLabel label = LIST_LABEL; label.setFont(list.getFont()); // JList actually has much more complex behavior here. // If rowHeight != -1 the rowHeight is either the max of all cell // heights (layout orientation != VERTICAL), or is variable depending // upon the cell. We assume a default size. // We could theoretically query the real renderer, but that would // not work for an empty model and the results may vary with // the content. if (rowHeight == -1) { rowHeight = label.getPreferredSize().height; } return getLabelBaseline(label, rowHeight) + list.getInsets().top; }
public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (index == -1) { Component comp = cellRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); return comp; } getTableListCellRendererModel().setRow(index); setComponentOrientation(list.getComponentOrientation()); if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else { setBackground(list.getBackground()); setForeground(list.getForeground()); } setEnabled(list.isEnabled()); setFont(list.getFont()); Border border = null; if (cellHasFocus) { if (isSelected) { border = UIManager.getBorder("List.focusSelectedCellHighlightBorder"); } if (border == null) { border = UIManager.getBorder("List.focusCellHighlightBorder"); } } else { border = getNoFocusBorder(); } setBorder(border); if (index == 0) { headerPanel.add(this); return headerPanel; } return this; }