blackberrybuttonfield

make button on the same size blackberry


I want to have two button in the same size one in the left and the other in the right. This is my code but I get button have the width more than the other

hManager = new HorizontalFieldManager(Field.USE_ALL_WIDTH|FIELD_VCENTER);
hManager.setPadding(15, 0, 15, 15);

B1= new ButtonField("B1", Field.FIELD_LEFT | ButtonField.CONSUME_CLICK ) {

    public int getPreferredWidth() {
      return 200;
    }
};

B2= new ButtonField("B2", Field.FIELD_RIGHT | ButtonField.CONSUME_CLICK ) {

    public int getPreferredWidth() {
        return 200;
    }
};

hmanager.add(B1);
hmanager.add(B2);

Solution

  • Do something like

    public int getPreferredWidth() {
        return (Display.getwidth()/2)-20 ;               
    }
    

    in your ButtonField.