tags:

views:

209

answers:

2

i am developing custom toolbar manager, but i want to adjust the fields alignment to be centered not aligned to the left , any advice

below is the code of toolbar

    package galaxy.bb.ui.container;

import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.XYEdges;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.decor.Background;
import net.rim.device.api.ui.decor.BackgroundFactory;
import net.rim.device.api.ui.decor.Border;
import net.rim.device.api.ui.decor.BorderFactory;

public class ToolBarManager extends HorizontalFieldManager {
private int bgColor = Color.BLACK;
private int borderColor = Color.WHITE;
private int borderStyle= Border.STYLE_FILLED;

public ToolBarManager(){
    super(USE_ALL_WIDTH);
    }
public ToolBarManager(int bgColor) {
    super(USE_ALL_WIDTH);
    this.bgColor = bgColor;
}
public ToolBarManager(int bgColor, int borderStyle) {
    super(USE_ALL_WIDTH);
    this.bgColor = bgColor;
    this.borderStyle = borderStyle;
}


public int getBgColor() {
    return bgColor;
}

public void setBgColor(int bgColor) {
    this.bgColor = bgColor;
}


public int getBorderColor() {
    return borderColor;
}

public void setBorderColor(int borderColor) {
    this.borderColor = borderColor;
}

public int getBorderStyle() {
    return borderStyle;
}

public void setBorderStyle(int borderStyle) {
    this.borderStyle = borderStyle;
}

protected void paint(Graphics graphics) {
    super.paint(graphics);
    XYEdges padding = new XYEdges(5, 5, 5, 5);

    Border roundedBorder = BorderFactory.createRoundedBorder(padding,
            borderColor, borderStyle);
    this.setBorder(roundedBorder);
    Background bg = BackgroundFactory.createSolidBackground(bgColor);
    this.setBackground(bg);

}

}
A: 

You can force the fields to be displayed in the center by specifying FIELD_HCENTER when creating each field. Or by using FIELD_HCENTER when creating the manager. In the latter case, the manager will be center itself, but each fields in it will be left-adjusted. It is mostly the same end results, but under some conditions it may be displayed differently.

ADB
A: 

y don't u go ahead with the positioning of the contents at the center position

for eg:

when i want to place any field at the center of screen then i do (Display.getWidth()-field.getWidth())/2

u can try positioning like this,if it helps in your case!!!!

SWATI