2012-10-05 3 views
3

Blackberry의 맞춤 라벨 필드를 사용하여 여러 줄로 텍스트를 표시하는 방법은 무엇입니까? 다음 코드를 사용하면 원하는 글꼴 크기로 레이블을 표시 할 수 있지만 범위가 제한되어 텍스트가 잘리지 않고 전체적으로 표시되지 않고 레이블 부분의 나머지 부분이 다음 줄에 표시되지 않는 문제가 있습니다 .Blackberry에서 사용자 정의 레이블 필드를 사용하여 여러 줄에 텍스트를 표시하는 방법은 무엇입니까?

여기에 도움을 주시면 감사하겠습니다.

다음은 사용자 정의 레이블 필드에 대한 코드입니다. 사용자 정의 필드의 폭과 높이를 제어

public class GrayBgLabelField extends LabelField { 

    private int width = Display.getWidth(); 
    private int height = 40; 
    private String label; 
    private Font font; 

    public GrayBgLabelField(){ 
     super(); 
    } 

    public GrayBgLabelField(String label, int fieldWidth){ 
     super(label, 0); 
     this.label = label; 
     width = fieldWidth;  
    } 

    public GrayBgLabelField(String label, int fieldWidth , long style){ 
     super(label, style); 
     this.label = label; 
     width = fieldWidth;  
    } 

    public GrayBgLabelField(String label, int fieldWidth , int fieldHeight){ 

     this(label,fieldWidth); 
     this.label = label; 
     height = fieldHeight; 
    } 

    public GrayBgLabelField(String label, int fieldWidth , int fieldHeight, long style){ 

     super(label, style); 
     this.label = label; 
     width = fieldWidth; 
     height = fieldHeight; 
    } 

    protected void layout(int maxWidth, int maxHeight) 
    {   
     super.layout(width, height); 
     setExtent(width, height); 
    } 

    protected void paint(Graphics g) { 

     if(font !=null){ 
      g.setFont(font); 
     } 

     if (label.length() != 0) {   
      g.drawText(label, width/30, height/4); 
     } 
     g.setColor(Color.BLACK); 

    } 

    public void setFont(int f){ 
     font = this.getFont().derive(f);   
    } 

    public void setFont(Font font){ 
     this.font = font; 
    } 

    protected void paintBackground(Graphics g) { 
     int oldColor = g.getColor(); 
     try { 
      g.setColor(0xF5F6F8); // Gray-DDDDDD color code. 
      g.fillRect(0, 0, getWidth(), getHeight());   
     } finally { 
      g.setColor(oldColor); 
     } 
    } 
} 
+0

시도해보십시오 - GrayBgLabelField g = new GrayBgLabelField ("your text"); g.setMargin (0,5,0,5); (이것은 텍스트의 왼쪽 및 오른쪽 여백을 설정합니다). – Signare

답변

2

재정의 방법. 여기

는 튜토리얼 : "How to create a custom field"

그리고 당신은 당신의 레이블 필드의 텍스트를 변경할 때, 화면에 필드 내용을 다시 그릴, invalidate() 방법을 통해 그것을 무효로합니다.

+0

라파엘, 고맙습니다. 나는 확실히 그것을 시도하고 업데이 트됩니다. –