LWUIT - 显示文本字段闪烁光标,即使该字段为空
我在表单中有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您希望文本字段处于编辑模式,而不是显示文本字段光标(编辑时会发生这种情况)。使用
requestFocus()
确保文本字段具有焦点,然后使用类似以下内容的内容: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:drawTextFieldCursor
方法有一个 Graphics 参数,因此绘制光标的方法是:public void Paint(Graphics g)
中派生 TextFieldThe
drawTextFieldCursor
method has a Graphics parameter , so the way you can draw your cursor is :public void paint(Graphics g)
you call drawTextFieldCursor after setting the drawing methods of the TextField's paint Graphic.