LWUIT - 显示文本字段闪烁光标,即使该字段为空

发布于 2024-12-05 12:05:39 字数 880 浏览 2 评论 0原文

我在表单中有一个 TextField 。默认情况下,此 TextField 应具有焦点, 效果很好。现在我希望用户意识到这一点并向他展示, 他位于 TextField 内 - 因此应该显示 TextField 光标 并眨眼。

我只在 DefaultLookAndFeel 中找到了 drawTextFieldCursor。但我有 完全不知道如何将其应用到我的 TextField 中。

任何帮助 - 和代码将不胜感激!


这是一个示例。我仍然没有发挥作用。

public void search2() {
    searchForm                      = new Form();
    TextField searchArea = new TextField();
    searchForm.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
    searchForm.addComponent(searchArea);
    searchArea.requestFocus();
    int i = Display.getInstance().getKeyCode(Display.GAME_FIRE);
    searchArea.keyPressed(i);
    searchArea.keyReleased(i);
    searchForm.show();
}

发生的情况是:TextField 获得焦点,可以直接编辑,显示“Abc”模式,但我真正想要的是向用户显示光标,所以他知道他在 TextField 内。这不会发生...如果有人可以向我展示一些工作代码...

I have a TextField in a Form. This TextField should have focus by default,
which works fine. Now I'd like the user to be aware of that and show him,
that he's inside the TextField - so the TextField cursor should be shown
and blink.

I only found drawTextFieldCursor in DefaultLookAndFeel. but I have
absolutely no idea how to apply this to my TextField.

Any help - and code would be appreciated!


Here's a sample. I still don't have it working.

public void search2() {
    searchForm                      = new Form();
    TextField searchArea = new TextField();
    searchForm.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
    searchForm.addComponent(searchArea);
    searchArea.requestFocus();
    int i = Display.getInstance().getKeyCode(Display.GAME_FIRE);
    searchArea.keyPressed(i);
    searchArea.keyReleased(i);
    searchForm.show();
}

What happens is: the TextField is focused, it can be directly edited, the "Abc" mode is shown, but what I really want is to show the user the cursor, so he KNOWS he's inside the TextField. This is not happening... if someone could show me some working code for that...

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

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

发布评论

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

评论(2

聚集的泪 2024-12-12 12:05:39

您希望文本字段处于编辑模式,而不是显示文本字段光标(编辑时会发生这种情况)。使用 requestFocus() 确保文本字段具有焦点,然后使用类似以下内容的内容:

int i = Display.getInstance().getKeyCode(Display.GAME_FIRE);
tf.keyPressed(i);
tf.keyReleased(i);

You want the text field to be in editing mode not for the text field cursor to show (which happens when editing). Use requestFocus() to make sure the text field has focus then use something like:

int i = Display.getInstance().getKeyCode(Display.GAME_FIRE);
tf.keyPressed(i);
tf.keyReleased(i);
对你再特殊 2024-12-12 12:05:39

drawTextFieldCursor 方法有一个 Graphics 参数,因此绘制光标的方法是:

  1. 在其 public void Paint(Graphics g) 中派生 TextField
  2. ,在设置绘图后调用 drawTextFieldCursor TextField 的绘制 Graphic 的方法。

The drawTextFieldCursor method has a Graphics parameter , so the way you can draw your cursor is :

  1. derive TextField
  2. in its public void paint(Graphics g) you call drawTextFieldCursor after setting the drawing methods of the TextField's paint Graphic.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文