开发者

Blackberry Editfield keep cursor on righthandside

开发者 https://www.devze.com 2023-03-08 23:48 出处:网络
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 th开发者_StackOverflowis.

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 th开发者_StackOverflowis.

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


You will have to create your own Manager, unfortunately. There is no simple or obvious way to do this.

A solution with source code was posted on the BlackBerry forums.


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

精彩评论

暂无评论...
验证码 换一张
取 消