黑莓 Editfield 将光标保持在右侧

发布于 2024-11-10 01:16:44 字数 979 浏览 0 评论 0原文

我想创建一个编辑字段,其光标保持在其右侧。
为了说明如果我想写“黑莓”,结果应该是这样的。

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

谢谢


由于缺乏声誉的无意义的事情,我无法回答我自己的问题。
无论如何,我找到了一个简单的方法。 width 指的是保存该编辑字段的管理器的宽度。

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

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

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

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

发布评论

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

评论(2

梨涡 2024-11-17 01:16:44

不幸的是,您必须创建自己的Manager。没有简单或明显的方法可以做到这一点。

A带有源代码的解决方案已发布在 BlackBerry 论坛上。

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.

開玄 2024-11-17 01:16:44

就像斯瓦蒂的解决方案一样。我确实是这样的:

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

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