Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Blackberry 自定义列表字段不';我画得不对_Blackberry_Alignment_Listfield - Fatal编程技术网

Blackberry 自定义列表字段不';我画得不对

Blackberry 自定义列表字段不';我画得不对,blackberry,alignment,listfield,Blackberry,Alignment,Listfield,我使用BSimpleTable添加了一个自定义listfield组件,我从这里获得: 不幸的是,该组件不支持内部字段的正确对齐,因此我尝试通过修改代码来添加它,如下所示: public class BSimpleRowRenderer extends Manager{ private int[] colWidthPercents; private int[] cellFrontPaddings; private int preferredHeight; public BSimpleRowRen

我使用BSimpleTable添加了一个自定义listfield组件,我从这里获得: 不幸的是,该组件不支持内部字段的正确对齐,因此我尝试通过修改代码来添加它,如下所示:

public class BSimpleRowRenderer extends Manager{
private int[] colWidthPercents;
private int[] cellFrontPaddings;
private int preferredHeight;

public BSimpleRowRenderer(long style,Field[] rowContents,int preferredHeight, 
 int[] colWidthPercents,int[] cellFrontPaddings){
    super(style);
    for (int col = 0; col < rowContents.length; col++) {
        add(rowContents[col]);
    }
    this.colWidthPercents = new int[rowContents.length];
    for(int i=0;i<colWidthPercents.length;i++){
        this.colWidthPercents[i] = colWidthPercents[i];
    }
    this.cellFrontPaddings = new int[rowContents.length];
    for(int i=0;i<cellFrontPaddings.length;i++){
        this.cellFrontPaddings[i] = cellFrontPaddings[i];
    }
    this.preferredHeight = preferredHeight;
}

protected void sublayout(int width, int height) {
    int x=0;
    int totalWidth = Display.getWidth();
    for (int col = 0; col < getFieldCount(); col++) {
        // Set the size and position of the current cell.
        Field curCellField = getField(col);
        XYPoint offset = calcAlignmentOffset(curCellField, Math.max(0,colWidthPercents[col]*totalWidth/100), Math.max(0, getPreferredHeight()));
        layoutChild(curCellField, width-x,getPreferredHeight());
        setPositionChild(curCellField, x+offset.x, 0);
        x+=(int)Math.floor((colWidthPercents[col]*totalWidth)/100); 
    }
    setExtent(Display.getWidth(), getPreferredHeight());
}

public void drawRow(Graphics g, int x, int y, int width, int height) {
    layout(width, height);
    setPosition(x, y);
    g.pushRegion(getExtent());
    subpaint(g);
    g.popContext();
}

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

public int getPreferredHeight() {
    return preferredHeight;
}

private XYPoint calcAlignmentOffset(Field field, int width, int height)
{
    XYPoint offset = new XYPoint(0, 0);
    long fieldStyle = field.getStyle();
    long field_x_style = fieldStyle & Field.FIELD_HALIGN_MASK;

    if (field_x_style == Field.FIELD_RIGHT){
        offset.x = width - field.getExtent().width;
    }
    else if (field_x_style == Field.FIELD_HCENTER){
        offset.x = (width - field.getExtent().width) / 2;
    }

    long field_y_style = fieldStyle & Field.FIELD_VALIGN_MASK;

    if (field_y_style == Field.FIELD_BOTTOM){
        offset.y = height - field.getExtent().height;
    }
    else if (field_y_style == Field.FIELD_VCENTER){
        offset.y = (height - field.getExtent().height) / 2;
    }

    return offset;
}
public类bsimplerowrender扩展管理器{
私有int[]冷宽百分比;
私家围板;
私人身高;
公共BSimpleRowRenderer(长样式,字段[]行内容,int首选高度,
int[]冷宽百分比,int[]单元正面填充){
超级(风格);
for(int col=0;col对于(int i=0;i如果表是您需要的,那么您可以尝试以下方法:。它对我非常有效。

谢谢您的回答,但更改组件是我最不想做的事情,当前组件已经足够好了,只是缺少正确的对齐支持。无论如何,谢谢。