2012-12-19 65 views
0

期間笨拙我有黑莓5點& 6點O的問題上模擬器 標籤字段變得笨拙,當我設置字體在黑莓 同一運行正常7標籤字段變成字體設置

這裏是我的樣本代碼

LabelField _lblTitle3 = 
     new LabelField(offerStatus, 
        USE_ALL_WIDTH | Field.FIELD_VCENTER | 
        LabelField.ELLIPSIS | Field.NON_FOCUSABLE) { 

     protected void drawFocus(Graphics graphics, boolean on) { 
     }; 

     protected void paintBackground(Graphics graphics) { 
      String offerStatus = _offerObj.getCategoryStatus(); 

      int color; 
      if (offerStatus.equalsIgnoreCase("Saved")) 
       color = Color.BLUE; 
      else if (offerStatus.equalsIgnoreCase("Accepted!")) 
       color = Color.GREEN; 
      else 
       color = Color.BLACK; 

      if (_isFocus) { 
       graphics.setColor(Color.WHITE); 
      } else { 
       graphics.setColor(color); 
      } 

      super.paint(graphics); 
     }; 
    }; 

    Font myFont = Font.getDefault(); 
    FontFamily typeface = FontFamily.forName("Times New Roman"); 
    int fType = Font.BOLD 
    int fSize = 12 
    myFont = typeface.getFont(fType, fSize); 
    _lblTitle3.setFont(myFont); 

圖片低於

See the Field overlap

回答

3

你想做什麼?只要改變字體顏色?

如果是這樣,您可能不想覆蓋paintBackground()

在執行paintBackground()的過程中,您需要撥打super.paint()。我不確定那會做什麼,但如果那是錯誤的,我不會感到驚訝。

paint()paintBackground()是兩個單獨的事情。

如果您只是想要改變字體顏色,取決於文本和焦點狀態,只需將該邏輯放在paint()方法中,並將paintBackground()單獨留下(不要覆蓋它)。另外,當您更改Graphics上下文時,要執行諸如設置新顏色之類的操作,通常先存儲舊顏色並稍後重置該顏色通常更安全。事情是這樣的:

 protected void paint(Graphics graphics) { 
      int oldColor = graphics.getColor(); 

      String offerStatus = _offerObj.getCategoryStatus(); 
      int color; 
      if (offerStatus.equalsIgnoreCase("Saved")) 
       color = Color.BLUE; 
      else if (offerStatus.equalsIgnoreCase("Accepted!")) 
       color = Color.GREEN; 
      else 
       color = Color.BLACK; 

      if (_isFocus) { 
       graphics.setColor(Color.WHITE); 
      } else { 
       graphics.setColor(color); 
      } 
      super.paint(graphics); 

      graphics.setColor(oldColor); 
     }; 
+0

它工作正常,謝謝 – Exhausted

+0

非常歡迎:) – Nate