2013-12-10 87 views
0

有什麼辦法,我可以將光標位置設置爲listgird文本框中的字符串結尾。 例子: 上listgird其將顯示單元格中輸入網站名稱,一旦用戶點擊的「http://」現在我想,我的光標位置到字符串的結尾>光標位置到listgird文本框中的字符串結尾?

+0

你看過嗎? http://stackoverflow.com/questions/511088/use-javascript-to-place-cursor-at-end-of-text-in-text-input-element – spg

+0

@Reddy問題與GWT或SmartGWT有關? – RAS

+0

@RAS與SmartGWT相關 – Reddy

回答

1

還是比較方便的。

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

有時您會在呈現完整組件時失去焦點。如果發生這種情況,可以嘗試將setFocus放入scheduleDeferred-Command中,這意味着在瀏覽器的渲染過程完成後,execute()中的代碼將被執行。所以你可以肯定,沒有其他組件會成爲焦點,你的組件再次失去它。

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()); 
     } 
    }); 
+0

即時通訊對不起..但我的問題是關於ListGrid不是關於TextBox的。 ListGrid沒有方法setCursorPos()。 – Reddy

相關問題