Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
amsiddh
Posts: 142
Registered: ‎06-26-2009
My Device: Not Specified
Accepted Solution

Custom TextBoxfield cursor problem in 9800

Hi,

 

The cursor in custom textboxfield is not getting updated properly. As you enter any text instead of showing cursor at the end of a character it  appears after one or two character space of last character and when you tap on textboxfield change the orientation then cursor comes to proper position. i.e at the end of the last character.

 

Even when i delete any character in textboxfield, it doesn't move smoothly. It fluctuate like moving forward and backward, shows the space between cursor and last character of text.

 

This behaviour i have seen only in  BB Torch 9800(Both device and simulator). Where as same code works in other devices like 9700,9000,9550,8520 all are of OS v5.0.

 

Here is my TextBoxField Code:

 

public class TextBoxField extends VerticalFieldManager 
{
    //Define some variables to be used
    //in the class
    private int managerWidth;
    private int managerHeight;
    private EditField editField;
    private String iText;
    private Graphics g1;
    private int myBorderColor;
    private int fillColor;
    private int width;
    private int height;
    
    //Pass in the fixed height and width for our object
    public TextBoxField(int width, int height)//, long style ) 
    {
        //This call to super will help keep the object in place
        super(Manager.NO_VERTICAL_SCROLL | Manager.USE_ALL_WIDTH);// | Manager.FIELD_HCENTER);
        
        this.width = width;
        this.height = height;
        managerWidth = Display.getWidth() - width;
        managerHeight = height;
        
        //vfm will allow scrolling within the object
        VerticalFieldManager vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.FIELD_VCENTER);
        
        
        editField = new EditField("", "", EditField.DEFAULT_MAXCHARS, EditField.FOCUSABLE)// | EditField.JUMP_FOCUS_AT_END)
        {
             public void paint(Graphics g) {
                 //This invalidation will help keep the border clean
                 //while scrolling
                 getManager().invalidate();
                 g.setColor(0xBCBEC0);
                 super.paint(g);
             }
             protected void onFocus(int direction) {
                myBorderColor = 0x469539;
                TextBoxField.this.invalidate();
             }

             protected void onUnfocus() {
                myBorderColor = 0x808285;//0x999999;
                TextBoxField.this.invalidate();
            }
        };
        
        vfm.add(editField);
        add(vfm);
   }
     
   public void paint(Graphics g) 
   { 
        managerWidth = Display.getWidth() - 50;
        
        if (managerWidth == 0) {
            managerWidth = width;
            
        }
        if (managerHeight == 0) {
            managerHeight = height;
        }
     
        //Draw a rectangle around out TextBoxField
        //For Border Color
        //int prevColor = g.getColor();
        int prevColor = g.getColor();
        g.setColor(myBorderColor);
        g.drawRoundRect(0, 0, managerWidth, getHeight(), 10, 10);
        g.setColor(prevColor);
         
        //Fills the Rectangle with  color
        g.setColor(Color.WHITE);
        g.fillRect(2, 2, managerWidth-4, getHeight()-4);
         
        super.paint(g);
        
    }
    
    
    //If this call to sublayout was made by the system then
    //both parameters would be passed with a value of 0.
    //This check and adjustment keeps the fixed properties
    //maintained.
    public void sublayout(int width, int height) 
    {
        managerWidth = Display.getWidth() - 50;
       // managerHeight = height;
        if (managerWidth == 0) {
            
            managerWidth = width;
            
        }
        if (managerHeight == 0) {
            managerHeight = height;
        }
        //managerWidth = Display.getWidth() - 50;
        //Force the extent of our manager.
        //This will force the height of the object
        //where the above super.sublayout() call will
        //set the width.
        
        super.sublayout(managerWidth, managerHeight);        
        setExtent(managerWidth,managerHeight);
    
    }


    //The following two methods allows users of the
    //TextBofField read and set its contents.
    public String getText() {
        return editField.getText();
    }

    public void setText(String text) {
        editField.setText(text);
    }
    public void setFont(Font font)
    {
        editField.setFont(font);
    }
    
    public void setFieldChangeListener(FieldChangeListener fl){
        editField.setChangeListener(fl);
    }
    
    public Field getField(){
        return editField;
    }

    
}

 

 

Please help me in solving this issue.

 

 

Thanks,

amsiddh.

 

Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: Custom TextBoxfield cursor problem in 9800

You are obviously using the old TextBoxField example, which has a number of problems, the worst one being:

        editField = new EditField("", "", EditField.DEFAULT_MAXCHARS, EditField.FOCUSABLE)// | EditField.JUMP_FOCUS_AT_END)
        {
             public void paint(Graphics g) {
                 //This invalidation will help keep the border clean
                 //while scrolling
                 getManager().invalidate();
                 g.setColor(0xBCBEC0);
                 super.paint(g);
             }

The highlighted code is the one causing the flickering.  It just happened not to affect the older phones too much, but it is a wrong code anyway.

 

I strongly suggest to review the following article which you can use as a much better starting point:

TextBoxField revisited

This article was created to address the problems with the old one. Make sure you read the comments - they have a couple of ideas about extending the functionality.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
amsiddh
Posts: 142
Registered: ‎06-26-2009
My Device: Not Specified

Re: Custom TextBoxfield cursor problem in 9800

Hi  arkadyz,

 

Thanks for ur reply.

 

Your link and suggetion are helped me to solve my issue. Now the TextBoxField working properly in all devices... :smileyhappy:

 

Thanks a lot.

 

 

Thanks,

amsiddh