2012-07-02 4 views
-1

가 나는 정의 내가 editfield에서 단어의 전체 라인을 입력하면, 그것은 원인 및 오류합니다 블랙 베리 editfield 오류

public class Custom_EditField extends EditField { 
int width, row; 

Custom_EditField(long style, int width, int row) { 
    super(style); 
    this.width = width; 
    this.row = row; 
} 

protected void layout(int width, int height) { 
    width = this.width; 
    height = this.row; 
    super.layout(width, Font.getDefault().getHeight() * row); 
    super.setExtent(width, Font.getDefault().getHeight() * row); 
} 

public int getPreferredHeight() { 
    return Font.getDefault().getHeight() * row; 
} 

public int getPreferredWidth() { 
    return width; 
} 

public void paint(Graphics graphics) { 
    super.paint(graphics); 
    graphics.setBackgroundColor(Color.GRAY); 
    graphics.clear(); 
    graphics.setColor(Color.BLACK); 
    int labelWidth = getFont().getAdvance(getLabel()); 
    graphics.drawRect(labelWidth, 0, getWidth() - labelWidth, getHeight()); 
    graphics.drawText(this.getText(), 0, 0); 
} 
} 

을 editfield했다. 자동 차선으로 갈 수없는 것 같습니다.

+1

는 "이 오류가 발생합니다을"당신은 당신이 얻을 수있는 오류를 설명 할 수 있습니까? 또한 [SSCCE] (http://pscode.org/sscce.html)가 도움이 될 것입니다. – Howard

+0

'0 : 21 : 21.476 : 앱 오류 104 0 : 21 : 21.478 : 캐치되지 않음 : StackOverflowError' –

답변

1

BlackBerry UI의 레이아웃 메소드에 대한 인수는 최대 값이며 사용자 정의 코드는 필드 범위를 설정할 때 이러한 최대 값을 고려하지 않습니다. 그러면 레이아웃에 문제가 발생할 것입니다. 또한 텍스트 래핑을 이해하지 못하기 때문에 paint() 메서드는 텍스트 필드의 드로잉을 변경하기에 최적의 방법이 아닙니다. 텍스트를 그리는 방법을 변경하려고하지만 래핑이 수행 된 후에는 drawText를 대신 정의하려고합니다.

이 당신이 원하는 약,하지만 당신은 당신이 예상대로 작동하도록 좀 더 미세 조정을 수행해야합니다

protected void layout(int maxWidth, int maxHeight) { 
    super.layout(maxWidth, Math.min(maxHeight, Font.getDefault().getHeight() * row)); 
    super.setExtent(maxWidth, Math.min(maxHeight, Font.getDefault().getHeight() * row)); 
} 

public int drawText(Graphics graphics, 
       int offset, 
       int length, 
       int x, 
       int y, 
       DrawTextParam drawTextParam) { 
    graphics.setBackgroundColor(Color.GRAY); 
    graphics.clear(); 
    graphics.setColor(Color.BLACK); 
    int labelWidth = getFont().getAdvance(getLabel()); 
    graphics.drawRect(labelWidth, 0, getWidth() - labelWidth, getHeight()); 
    graphics.drawText(this.getText().substring(offset, offset + length), x, y); 
} 
+0

텍스트를 그립니다. 무엇을 반환합니까? –

+0

'0 : 21 : 21.476 : 앱 오류 104 0 : 21 : 21.478 : 캐치되지 않음 : StackOverflowError' –