001package jmri.util.swing;
002
003import java.awt.Component;
004import java.util.List;
005import javax.swing.DefaultListCellRenderer;
006import javax.swing.JComponent;
007import javax.swing.JList;
008
009/**
010 * Set ToolTips for ComboBox items
011 *
012 * Steve Young (c) 2019
013 *
014 */
015public class ComboBoxToolTipRenderer extends DefaultListCellRenderer {
016    List<String> tooltips;
017
018    @Override
019    public Component getListCellRendererComponent(JList<?> list, Object value,
020        int index, boolean isSelected, boolean cellHasFocus) {
021
022        JComponent comp = (JComponent) super.getListCellRendererComponent(list,
023            value, index, isSelected, cellHasFocus);
024
025        if (-1 < index && null != value && null != tooltips) {
026            list.setToolTipText(tooltips.get(index));
027        }
028        return comp;
029    }
030
031    /**
032     * Set ToolTips for the ComboBox
033     *
034     * @param tooltips a List of Strings to be used for the Tooltips
035     */
036    public void setTooltips(List<String> tooltips) {
037        this.tooltips = tooltips;
038    }
039}