Monday, January 17, 2011

Using image for a TextEditField in Blackberry

Hello all,
 
When i started coding for basic edit field in blackberry i found 
that it is transparent but the look was not exactly that i wanted. 
I wanted a look of TextEditField that appears in websites 
so i tried the below mentioned code. 
May be it can help to any blackberry developer.
 
Here is the code:
 
LabelField label = new LabelField("name");

textbox=new EditField("","",500, 
 EditField.NO_NEWLINE|Field.FOCUSABLE) 
 {
  protected void paint(Graphics g)
   {
     g.setColor(Color.MAROON);
     super.paint(g);
   }
  protected boolean keyChar(char key, int status, int time) 
   {
     return super.keyChar(key, status, time);
   }
 };


 manager = new VerticalFieldManager(HORIZONTAL_SCROLL )
  {
    protected void paint(Graphics g) 
     {
      int x = this.getHorizontalScroll();
      if(textbox.getText().equals(""))
      {
        g.drawBitmap( x, 0, textbox_img.getWidth(), 
           textbox_img.getHeight(),textbox_img, 0, 0 );
      }
     super.paint(g);
   }
}
manager.add(textbox);
 
add(label);
add(manager); 
 
now add this manager in your main screen and see how it looks.
Its even supports horizontal scroll.
  
Look at this:
 
 
  
  
  
 
 
 

5 comments:

  1. hello sir
    it shows me
    error: ';' expected
    }
    ^

    while i copy all the code

    ReplyDelete
  2. manager = new VerticalFieldManager(HORIZONTAL_SCROLL )
    {
    protected void paint(Graphics g)
    {
    int x = this.getHorizontalScroll();
    if(textbox.getText().equals(""))
    {
    g.drawBitmap( x, 0, textbox_img.getWidth(),

    textbox_img.getHeight(),textbox_img, 0, 0 );
    }
    super.paint(g);
    }
    }; // semi colon was missing here, try this....

    ReplyDelete
  3. Hi SweetCynaiDe,

    saw ur code.NEed to ask few questions
    1) try to debug your code and check what does String responseStr[] = Utility.split(response); method returns.

    2) after that check the zeroth index value of responseStr array.I doubt that the first element of the array is not "true" or if it returns "true" then instead of if(responseStr[0].equals("true")) you should use if(responseStr[0].equalsIgnorecase("true")).

    3) Use printlns to see the logs in console.

    Hope it helps.
    If you have posted question i any forum like stack overflow or BB developer forums etc.. do send me the link.

    :)

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete