Blackberry EditField - 高度改变无效

发布于 2024-11-03 09:31:44 字数 1617 浏览 0 评论 0原文

我尝试做的就是简单地更改 EditField 的高度。 这听起来很简单,但我面临着一个让我发疯的问题。 这是我的代码:

public class CMainManager extends HorizontalFieldManager
{
    EditField mtxt=new EditField(EditField.FOCUSABLE | EditField.FILTER_DEFAULT);

    /* Constructeur */
    public CMainManager()
    {
        add(mtxt);
    }

     public int getPreferredHeight()
     {
          return Display.getHeight();
    }

    public int getPreferredWidth()
    {
          return Display.getWidth();
    }

    protected void sublayout(int width, int height)
    {
        layoutChild(mtxt, 50, 500);
        setPositionChild(mtxt, 0, 10);
        mtxt.setBackground(
                BackgroundFactory.createSolidBackground(0x000000FF));

        setExtent(width, height);
    }
}

行layoutChild(mtxt, 50, 500);应该设置我的 EditField 的宽度和高度。确实如此,但仅限于宽度。高度是恒定的。如果我将其设置为 500,我会得到与将其设置为 10 相同的结果。

知道我缺少什么吗?因为我确信这是我正在做的一个愚蠢的错误...

谢谢

==编辑

在 jproffit 帮助之后,我明白了我做错了什么。然而现在它可以工作了(我可以设置高度)我有另一个问题。这是我的代码:

private EditField m_Txt=new EditField(EditField.FOCUSABLE |
                                        EditField.FILTER_DEFAULT) {
    protected void layout(int width, int height)
    {
        setExtent(Display.getWidth(), m_TxtHeight);
    }
    public boolean isFocusable()
    {
        return true;
    }

    protected void onFocus(int direction)
    {
        super.onFocus(direction);
        invalidate();
    }

    protected void onUnfocus() {
        super.onUnfocus();
        invalidate();
    }
};

使用此代码我无法正确管理焦点。我忘记了什么?我在我的字段中看不到光标。

有什么想法吗?

谢谢

What I try to do is to simply change the height of an EditField.
This sounds pretty easy but I facing a problem that drives me crazy.
Here is my code:

public class CMainManager extends HorizontalFieldManager
{
    EditField mtxt=new EditField(EditField.FOCUSABLE | EditField.FILTER_DEFAULT);

    /* Constructeur */
    public CMainManager()
    {
        add(mtxt);
    }

     public int getPreferredHeight()
     {
          return Display.getHeight();
    }

    public int getPreferredWidth()
    {
          return Display.getWidth();
    }

    protected void sublayout(int width, int height)
    {
        layoutChild(mtxt, 50, 500);
        setPositionChild(mtxt, 0, 10);
        mtxt.setBackground(
                BackgroundFactory.createSolidBackground(0x000000FF));

        setExtent(width, height);
    }
}

The line layoutChild(mtxt, 50, 500); should set the width and height of my EditField. It does, but only with the width. The height is constant. If I set it to 500 I get the same result as if I set it to 10.

Any idea of what I'm missing ? because I'm sure this is a stupid error I'm doing...

Thanks

==edit

After jproffit help, I've understood what I did wrong. However now that it works (I can set the height) I have another problem. Here is me code:

private EditField m_Txt=new EditField(EditField.FOCUSABLE |
                                        EditField.FILTER_DEFAULT) {
    protected void layout(int width, int height)
    {
        setExtent(Display.getWidth(), m_TxtHeight);
    }
    public boolean isFocusable()
    {
        return true;
    }

    protected void onFocus(int direction)
    {
        super.onFocus(direction);
        invalidate();
    }

    protected void onUnfocus() {
        super.onUnfocus();
        invalidate();
    }
};

With this code I cannot manage the focus correctly. What do I forget ? I cannot see the cursor in my field.

Any idea ?

Thanks

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

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

发布评论

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

评论(2

混浊又暗下来 2024-11-10 09:31:44

您不是告诉它要占用的尺寸,而是指定它可以占用的最大空间量。因此,当你告诉它 10、50 或 500 时,如果它只想使用 8 的高度,就这样。如果您还想控制 EditField 的尺寸,则必须重写 EditField 上的 layout()

You aren't telling it the dimensions to take, you're specifying the maximum amount of space it can take up. So when you tell it 10, 50, or 500, if it only want to use a height of 8 that's all it will be. You'll have to override layout() on the EditField if you want to control its dimensions as well.

灵芸 2024-11-10 09:31:44

尝试这样做..
创建自定义编辑字段并在布局方法内

_editField = new EditField("", initialValueOfTextField) 
    {
        protected void layout(int maxWidth, int maxHeight) 
        {
          int myWidth = getMaxSize() * getFont().getAdvance("W");// define your req width
          int myHeight= 50 // your required height
          super.layout(myWidth, myHeight);
       }
   };

Try doing like this..
create a custom editfield and inside the layout method

_editField = new EditField("", initialValueOfTextField) 
    {
        protected void layout(int maxWidth, int maxHeight) 
        {
          int myWidth = getMaxSize() * getFont().getAdvance("W");// define your req width
          int myHeight= 50 // your required height
          super.layout(myWidth, myHeight);
       }
   };
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文