2011-02-24 116 views

回答

0

在黑莓,你可以通過的情況下,從現場

public class MyField extends Field { 
     public void layout(int width, int height){ 
      setExtent(width, height); //set the field size 
     } 
     public void pain(Graphics g){ 
      //do your own paint here 
      //g.drawText ("Test", 0, 0); 
     } 
    } 

擴展你想創建由一個labelField和文本字段的創建自定義組件,我建議你從文本字段

public class InputField extends TextField { 
     private String _label; 
     private TextField _text; 
     public InputField(String label){ 
      _label = label; 
     } 

     public void layout(int width, int height){ 
      setExtend(width + 200, height); //just an example, i add 200 pixel for width 
      //you can get the width of the _label too 
      //need other functions to get width based on the String 
     }   

     //you override how to paint in screen 
     public void paint(Graphics g){ 
      super.paint(g); 
      g.drawText (getLeft()-200, getTop(), _label);        
     } 
    } 

見延伸更多示例 http://supportforums.blackberry.com/t5/Java-Development/Custom-Control/td-p/159699