鼠标悬停至JComboBox中的某个选项时,显示提示信息
新建ComboboxToolTipRenderer 类:
import java.awt.Component;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JList;
public class ComboboxToolTipRenderer extends DefaultListCellRenderer{
public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus) {
JComponent comp = (JComponent) super.getListCellRendererComponent(list,
value, index, isSelected, cellHasFocus);
if (comp instanceof JLabel) {
JLabel label = (JLabel) comp;
label.setToolTipText("提示信息!");
}
return comp;
}
}
使用Co