编辑字段的对齐

发布于 2024-12-04 17:27:16 字数 3596 浏览 0 评论 0原文

我已经创建了一个标签和 RoundedEditField。但是我无法在黑莓中的标签下以特定的边距制作该 RoundedEditField。 怎么办呢.. 听到的是代码

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 
         }
    }

i have created one lable and RoundedEditField.but i am not able to make that RoundedEditField under the lable in blackberry with spcific margin.
How to do that..
hear is Code

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 
         }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

难以启齿的温柔 2024-12-11 17:27:16

如果您希望它位于 LabelField 下,则需要将它们放入 VerticalFieldManager 而不是 Horizo​​ntalFieldManager 中。这应该对您有用:

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);

顺便说一句,您可以考虑创建一个 RoundedBasicEditField (或任何您想要的名称)类,这样您就不必在代码中保留匿名类 BasicEditField (使代码更具可读性,更容易如果您发现其他想做的事情,则对所有这些进行更改)。

If you're wanting it to be under the LabelField, you'll need to put them in a VerticalFieldManager rather than a HorizontalFieldManager. This should work for you:

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);

On a side note, you may consider creating a RoundedBasicEditField (or whatever name you'd like) class so you don't have to keep anonymous classing BasicEditField inside the code (makes the code more readable, and easier to implement changes for all of them if you find something else you want to do).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文