views:

22

answers:

1

Hi all

I have created a custom button and i am placing the bunch of Custombuttons in a verticalfieldManager , I have aligned the verticalField Manager in the center. when i am creating a default buttonField then verticalfield Manager is able to align the buttonfield in the center. but when i am assigning custombuttonfield in the verticalField Manager it's not aligning in the center.

here is my custombuttoncode

enter code herepublic CustomButtonField(String label,long style) {
    super(style);
    this.label = label;
    onPicture = Bitmap.getBitmapResource(onPicturePath);
    font = getFont();
    this.setPadding(5,5, 5, 5);
}

public String getLabel() {
    return label;   
}

public int getPreferredHeight() {
    return onPicture.getHeight();
}

public int getPreferredWidth() {
    return onPicture.getWidth();
}

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

protected void paint(Graphics graphics) {
    int texty =(getHeight()-getFont().getHeight())/2;

    if (isFocus()) {
        graphics.setColor(Color.BLACK);
        graphics.drawBitmap(0, 0, getWidth(), getHeight(),onPicture , 0, 0);
        graphics.setColor(Color.WHITE);
        graphics.setFont(font);
        graphics.drawText(label,0,texty,DrawStyle.ELLIPSIS,getWidth());
    } else {
        graphics.drawBitmap(0, 0, getWidth(), getHeight(),onPicture , 0, 0);
        graphics.setColor(Color.WHITE);
        graphics.setFont(font);
        graphics.drawText(label,0,texty,DrawStyle.ELLIPSIS,getWidth());
    }
}

public boolean isFocusable() {
    return true;
}

protected void onFocus(int direction) {
    super.onFocus(direction);
    invalidate();
}

protected void onUnfocus() {
    super.onUnfocus();
    invalidate();
}

protected boolean navigationClick(int status, int time) {
    fieldChangeNotify(0);
    return true;
}

protected boolean keyChar(char character, int status, int time) {
    if (character == Keypad.KEY_ENTER) {
        fieldChangeNotify(0);
        return true;
    }
    return super.keyChar(character, status, time);
}

}

A: 

When you create the button you need to pass the Field.FIELD_HCENTER flag as one of your style flags.

CustomButtonField button = new CustomButtonField("TestLabel", Field.FIELD_HCENTER);
redwoolf