1 19 package org.netbeans.modules.web.wizards; 20 21 import java.awt.Component ; 22 import java.awt.event.ItemEvent ; 23 import java.awt.event.ItemListener ; 24 import javax.swing.JComboBox ; 25 import javax.swing.JLabel ; 26 import javax.swing.JList ; 27 import javax.swing.ListCellRenderer ; 28 29 class ToolTipCombo extends JComboBox { 30 31 private final static boolean debug = false; 32 33 private static final long serialVersionUID = 1189442122448524856L; 34 35 ToolTipCombo(Object [] o) { 36 super(o); 37 this.setRenderer(new PathRenderer()); 38 addItemListener(new ItemListener () { 39 public void itemStateChanged(ItemEvent evt) { 40 if(evt.getStateChange() == ItemEvent.SELECTED) { 41 setToolTipText(evt.getItem().toString()); 42 } 43 } 44 }); 45 if(o != null && o.length > 1) 46 setToolTipText(o[0].toString()); 47 } 48 49 private void log(String s) { 50 System.out.println("ToolTipCombo" + s); 51 } 52 53 class PathRenderer extends JLabel implements ListCellRenderer { 54 55 private static final long serialVersionUID = 1323260132420573174L; 56 57 public PathRenderer() { 58 setOpaque(true); 59 } 60 61 public Component getListCellRendererComponent(JList list, 62 Object value, 63 int index, 64 boolean isSelected, 65 boolean cellHasFocus) { 66 67 if(debug) log("::getListCellRendererComponent()"); if(debug) log("\t" + value.toString()); setText(value.toString()); 70 setToolTipText(value.toString()); 71 return this; 72 } 73 } 74 } 75 76 | Popular Tags |