现在的位置: 首页 > 综合 > 正文

如何让JComboBox下来出来的菜单大于本身的宽度!

2018年01月30日 ⁄ 综合 ⁄ 共 546字 ⁄ 字号 评论关闭

如何让JComboBox下来出来的菜单大于本身的宽度!
因为设定了JComboBox宽度,所以如果下拉选项的内容特别多,就显示不出来了,有没有办法让它都显示出来?

 

 public class WideComboBox extends JComboBox{    
    
    public WideComboBox() {    
    }    
    
    public WideComboBox(final Object items[]){    
        super(items);    
    }    
    
    public WideComboBox(Vector items) {    
        super(items);    
    }    
    
    public WideComboBox(ComboBoxModel aModel) {    
        super(aModel);    
    }    
    
    private boolean layingOut = false;    
    
    public void doLayout(){    
        try{    
            layingOut = true;    
            super.doLayout();    
        }finally{    
            layingOut = false;    
        }    
    }    
    
    public Dimension getSize(){    
        Dimension dim = super.getSize();    
        if(!layingOut)    
            dim.width = Math.max(dim.width, getPreferredSize().width);    
        return dim;    
    }    
}  

抱歉!评论已关闭.