Shikhar13 / codenameone

Automatically exported from code.google.com/p/codenameone
0 stars 0 forks source link

The width of a combobox is calculated incorrectly. #256

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The width of a combobox is calculated incorrectly.

public Dimension getComboBoxPreferredSize(List cb) {
        Dimension d = getListPreferredSize(cb);
        if (comboImage != null) {
            d.setWidth(d.getWidth() + comboImage.getWidth());
            d.setHeight(Math.max(d.getHeight(), comboImage.getHeight()));
        }
        return d;
    }

Now Dimension d = getListPreferredSize(cb) calls this:

public Dimension getListPreferredSize(List l) {

which calls this:

private Dimension getListPreferredSizeImpl(List l) {

 // If combobox without ever importing the ComboBox class dependency
        if(l.getOrientation() > List.HORIZONTAL) {
            int boxWidth = l.getStyle().getFont().getHeight() + 2;
            return new Dimension(boxWidth + selectedWidth + horizontalPadding, selectedHeight + verticalPadding);
        } else {
            if (l.getOrientation() == List.VERTICAL) {
                return new Dimension(selectedWidth + horizontalPadding, selectedHeight + (height + l.getItemGap()) * (numOfcomponents - 1) + verticalPadding);
            } else {
                return new Dimension(selectedWidth + (width + l.getItemGap()) * (numOfcomponents - 1) + horizontalPadding, selectedHeight + verticalPadding);
            }
        }

As you can see if(l.getOrientation() > List.HORIZONTAL) { results in adding a 
box width (which is anyway calculated incorrectly since comboImage was not 
checked. Then after the getListPreferredSizeImpl call we return to the root 
which again adds a box (this time correctly).

Original issue reported on code.google.com by jkoo...@gmail.com on 12 Jul 2012 at 3:59

GoogleCodeExporter commented 9 years ago
Assigning to Chen since he looked at this a while back.

Original comment by shai.almog on 13 Jul 2012 at 3:56