0

Is there any way by which, i can set the cursor position to end of string in listgird textbox. Example : Enter website name, once user click on cell of listgird its will display 'http://' now i want that my cursor position to the end of string.>

Reddy
  • 65
  • 1
  • 10

1 Answers1

1

it is quite easy:

    TextBox yourBox = new TextBox();
    root.add(yourBox);
    yourBox.setValue("AMSTERDAM");
    yourBox.setFocus(true);
    yourBox.setCursorPos(yourBox.getValue().length());

sometimes you lose anyway the focus while rendering the complete component. If this happens you can try to put the setFocus in a scheduleDeferred-Command, it means, after the rendering process of the browser is done, the code in execute() will be executed. So you can be sure, that no other component will get also a focus, and your component lose it again.

    final TextBox yourBox = new TextBox();
    root.add(yourBox);
    yourBox.setValue("AMSTERDAM");
    Scheduler.get().scheduleDeferred(new ScheduledCommand()
    {
        @Override
        public void execute()
        {
            yourBox.setFocus(true);
            yourBox.setCursorPos(yourBox.getValue().length());
        }
    });
  • im sorry..but my question was about ListGrid not about TextBox. ListGrid doesnt have the method setCursorPos(). – Reddy Dec 12 '13 at 06:57