当前位置:编程学习 > 网站相关 >>

JComboBox渲染

JComboBox 的渲染,直接放在上面给出提示。
 
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sunny_tec_feng;
import java.awt.Component;
import java.util.Vector;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
/**  www.zzzyk.com
 *
 * @author adm
 */
public class ToolTipComboBox extends JComboBox {
    public ToolTipComboBox(ComboBoxModel aModel) {
        super(aModel);
        render render1 = new render();
        setRenderer(render1);
    }
    public ToolTipComboBox(Object[] items) {
        super(items);
        render render1 = new render();
        setRenderer(render1);
    }
    public ToolTipComboBox(Vector<?> items) {
        super(items);
        render render1 = new render();
        setRenderer(render1);
    }
    public ToolTipComboBox() {
        render render1 = new render();
        setRenderer(render1);
    }
    class render extends DefaultListCellRenderer {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            JLabel listCellRendererComponent = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            listCellRendererComponent.setToolTipText(String.valueOf(value));
            return listCellRendererComponent;
        }
    }
}
 
 
补充:综合编程 , 其他综合 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,