I have an editable JComboBox
which contains a list of single letter values. Because of that the combobox is very small.
Every letter has a special mean
Here is a great solution by Santhosh Kumar, without the need to mess with UI's and other nasty stuff like that!
http://www.jroller.com/santhosh/entry/make_jcombobox_popup_wide_enough
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;
}
}