开发者

LWUIT - show TextField blinking Cursor, even if the field is empty

I have a TextField in a Form. This TextField should have focus by default, which works fine. Now I'd l开发者_开发技巧ike 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...


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


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.
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜