views:

22

answers:

1

I'm creating a simple blackberry application for testing purposes and my custom buttons do not show on the UI of the simulator.

I've created a custom button called CustomButtonField and here is the code:

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);
    }

}

And here is where I invoke it and display it:

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.

What am I doing wrong?

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

setExtend is set to 0, 0 all the time.

endevour