Пользовательские кнопки не отображаются в моем интерфейсе - PullRequest
0 голосов
/ 03 сентября 2010

Я создаю простое приложение blackberry для тестирования, и мои пользовательские кнопки не отображаются в пользовательском интерфейсе симулятора.

Я создал пользовательскую кнопку с именем CustomButtonField, и вот код:

package test.expense;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;

public class CustomButtonField extends Field {
    String label;
    int backgroundColor;
    int foregroundColor;

    public CustomButtonField(String label, int backgroundColor, int foregroundColor, long style){
        super(style);
        this.label = label;
        this.backgroundColor = backgroundColor;
        this.foregroundColor = foregroundColor;
    }

    public int getPreferedHeight(){
        return getFont().getHeight() + 8;
    }

    public int getPreferedWidth(){
        return getFont().getAdvance(label) + 8;
    }

    protected void layout(int width, int height) {
        setExtent(Math.min(width, getPreferredWidth()), Math.min(height, getPreferredHeight()));
    }

    protected void paint(Graphics graphics) {
        graphics.setColor(backgroundColor);
        graphics.fillRoundRect(1, 1, getWidth()-2, getHeight()-2, 12, 12);
        graphics.setColor(foregroundColor);
        graphics.drawText(label, 4, 4);
    }

}

И вот где я вызываю и показываю это:

HorizontalFieldManager buttonManager = new HorizontalFieldManager(FIELD_RIGHT);
CustomButtonField btnCancel;
CustomButtonField btnSubmit;

public ExpenseSheetScreen() {
    super();
        btnCancel = new CustomButtonField("Cancel", Color.WHITE, 0x716eb3, 0);
    btnCancel.setChangeListener(this);
    btnSubmit = new CustomButtonField("Submit", Color.WHITE, 0x716eb3, 0);
    btnSubmit.setChangeListener(this);

    buttonManager.add(btnCancel);
    buttonManager.add(btnSubmit);

    add(buttonManager);
}// End Expense Sheet Screen.

Что я делаю не так?

1 Ответ

0 голосов
/ 09 сентября 2010
 protected void layout(int width, int height) {
    setExtent(Math.min(width, getPreferredWidth()), 
    Math.min(height, getPreferredHeight()));
 }

setExtend всегда имеет значение 0, 0.

...