blackberryblackberry-jdeblackberry-editfield

Blackberry Editfield keep cursor on righthandside


I want to create an editfield whose cursor keeps at righthandside of it.
To illustrate if i want to write "blackberry", result should be like this.

<-----------width-of-editfield------>
                                    b
                                   bl
                                  bla
                                 blac
                                black
                               blackb
                              blackbe
                             blackber
                            blackberr
                           blackberry

Thanks


Because of non-sense of lack of reputation thing, i can not answer my own question.
Any way, I found an easy way. width refers to width of the manager which holds this edit field.

editField = new EditField("","",maxChars,EditField.NO_NEWLINE | EditField.NON_SPELLCHECKABLE){
        protected boolean keyChar(char key, int status, int time) {
        editField.setPadding(0, 0, 0, width - (getFont().getAdvance(this.getText())) - 10);
        invalidate();
        return super.keyChar(key, status, time);
    }
};

Solution

  • Just like Swati's solution. I did like this:

    editField = new EditField("", "", maxChars, EditField.NO_NEWLINE | EditField.NON_SPELLCHECKABLE){
        protected boolean keyChar(char key, int status, int time){
            switch (key){
                case Characters.BACKSPACE:{
                    try {
                        text = text.substring(0,text.length()-1);
                        invalidate();
                    } catch (IndexOutOfBoundsException e) {}
                    return true;
                }
            }
            text = text + key;
            invalidate();
            return true;
        }
        protected void paint(Graphics graphics) {
            graphics.drawText(text,0, 0, DrawStyle.RIGHT, width - 10);
            super.paint(graphics);
        }
    };