欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

How to make your ComboBox more wider enough

程序员文章站 2022-04-12 13:14:12
...


import javax.swing.*;
import java.awt.*;
import java.util.Vector;

// got this workaround from the following bug:
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4618607
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;
}
}



Here is the original source of this article:

[url]http://www.jroller.com/santhosh/entry/make_jcombobox_popup_wide_enough[/url]
相关标签: Swing ComboBox