1 package com.ca.commons.cbutil; 2 3 import javax.swing.*; 4 import javax.swing.plaf.basic.BasicComboBoxRenderer ; 5 import java.awt.*; 6 7 8 14 15 public class CBBasicComboBoxRenderer extends BasicComboBoxRenderer 16 { 17 public Object [] text; 19 24 25 public CBBasicComboBoxRenderer(Object [] txt) 26 { 27 super(); 28 text = txt; 29 } 30 31 49 50 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) 51 { 52 if (isSelected) 53 { 54 setBackground(list.getSelectionBackground()); 55 setForeground(list.getSelectionForeground()); 56 57 if (index > -1) 58 { 59 list.setToolTipText(value.toString()); setText(text[index].toString()); } 62 } 63 else 64 { 65 setBackground(list.getBackground()); 66 setForeground(list.getForeground()); 67 } 68 setFont(list.getFont()); 69 setText((value == null) ? "" : value.toString()); 70 return this; 71 } 72 } | Popular Tags |