2011-09-15 6 views
0

J'ai créé un lable et RoundedEditField, mais je ne suis pas en mesure de faire ce RoundedEditField sous lable dans blackberry avec une marge spécifique. Comment le faire .. entendre est le CodeAlignement de EditField

enter code here 
public class MyClass extends MainScreen implements FieldChangeListener { 


ButtonField next; 
    Bitmap bit; 
    //String emp_id,emp_name,salary; 

     public MyClass() 
    { 
    bit=Bitmap.getBitmapResource("PlainScreen.png"); 
    VerticalFieldManager v_mgr=new VerticalFieldManager() 
    //HorizontalFieldManager h_mgr = new HorizontalFieldManager() 
     { 
     protected void paint(Graphics graphics) 
     { 
     graphics.drawBitmap(0, 0, Display.getWidth(),Display.getHeight(), bit, 0, 0); 
     super.paint(graphics); 
     } 
     protected void sublayout(int maxWidth, int maxHeight) //It fit the image to     device width and height. 
     { 
     super.sublayout(Display.getWidth(),Display.getHeight()); 
     setExtent(Display.getWidth(),Display.getHeight()); 
    } 
    }; 


     HorizontalFieldManager hSecond = new HorizontalFieldManager(USE_ALL_WIDTH); 
     /*BasicEditField roundedBorderEdit = new BasicEditField(); 
     XYEdges padding = new XYEdges(15, 15, 15, 15); 
     int color = Color.WHITE; 
     int lineStyle = Border.STYLE_FILLED; 
     Border roundedBorder = BorderFactory.createRoundedBorder(padding, 
      color, lineStyle); 
     roundedBorderEdit.setBorder(roundedBorder); 
     */ 
    LabelField lbl= new LabelField("LastName:", LabelField.FIELD_HCENTER | LabelField.NON_FOCUSABLE){ 
    protected void paint(Graphics g) 
    { 
     Font font1 = getFont(); 
     g.setColor(Color.WHITE); 
     super.paint(g); 
    }}; 

     BasicEditField lblName = new BasicEditField(" ","",50,BasicEditField.FIELD_HCENTER) 
    { 

     protected void paint(Graphics graphics) 
    { 
     Font font= getFont(); 
     graphics.drawRoundRect(0, 0, 240, font.getHeight(), 30, 30); 
     graphics.setColor(Color.BLACK); 
     super.paint(graphics); 
     graphics.setColor(Color.WHITE); 
     super.paint(graphics); 
     } 
     }; 
     hSecond.add(lbl); 
     hSecond.add(lblName); 
     hSecond.setMargin(0, 0, 0, 50); 
     hSecond.setPadding(5, 30, 20, 0); 
     v_mgr.add(hSecond); 
     //v_mgr.setPadding(0, 0, 0, 10); 
     HorizontalFieldManager hThird = new HorizontalFieldManager(USE_ALL_WIDTH); 
     LabelField lbl1= new LabelField("Number:",LabelField.FIELD_HCENTER |  LabelField.NON_FOCUSABLE){ 
      protected void paint(Graphics g) 
      { 
      Font font = getFont(); 
      g.setColor(Color.WHITE); 
      super.paint(g); 
      }}; 
     BasicEditField lblName1 = new BasicEditField("  ","",50,BasicEditField.FIELD_HCENTER) 
    { 
     protected void paint(Graphics graphics) { 
       Font font1= getFont(); 
       graphics.drawRoundRect(0, 0, 240, font1.getHeight(), 30, 30); 
       graphics.setColor(Color.BLACK); 
       super.paint(graphics); 
     graphics.setColor(Color.WHITE); 
     super.paint(graphics); 
     } 
     }; 
     //lblEmail.setFont(StaticVariables.font2); 
     hThird.add(lbl1); 
     hThird.add(lblName1); 
     hThird.setMargin(0, 0, 0, 50); 
     //PasswordEditField txtEmail = new PasswordEditField(); 
     //hThird.add(txtEmail); 
     hThird.setPadding(5, 30, 20, 0); 
     v_mgr.add(hThird); 
     //v_mgr.setPadding(0, 0, 0, 10); 
    add(v_mgr); 
     } 
     public void fieldChanged(Field field, int context) 
     { 
     // TODO Auto-generated method stub 
     } 
    } 
+0

s'il vous plaît poster votre code pour résoudre le problème – koti

Répondre

2

Si vous le vouloir être sous labelField, vous aurez besoin de les mettre dans un VerticalFieldManager plutôt qu'un HorizontalFieldManager. Cela devrait fonctionner pour vous:

VerticalFieldManager vfm = new VerticalFieldManager(); 
LabelField lbl = new LabelField("Last Name:"); 
lbl.setMargin(0, 0, yourMargin, 0); 
BasicEditField lblName = new BasicEditField() { // your rounded code }; 
vfm.add(lbl); 
vfm.add(lblName); 
hfmSecond.add(vfm); 

Sur une note côté, vous pouvez envisager de créer un RoundedBasicEditField (ou quel que soit le nom que vous souhaitez) classe afin que vous ne devez pas garder BasicEditField de classage anonyme à l'intérieur du code (marques le code est plus lisible, et plus facile à mettre en œuvre des changements pour chacun d'entre eux si vous trouvez quelque chose d'autre que vous voulez faire).