2010-06-24 36 views
2

我正在使用SuggestBox讓用戶選擇值。 但是,當列表中只有一個值時,我將在SuggestBox中設置值,並且我希望該字段不可編輯。如何在GWT中禁用SuggestBox

我想下面的東西,但現在組件在用戶界面上不可見。

sgstBox.getTextBox().setEnabled(false); 

這是不工作或者

sgstBox.getTextBox().setReadOnly(true); 

回答

3

兩個未測試的解決方案found on Google groups

public static void setEnabled(SuggestBox sb,boolean enabled) { 
       DOM.setElementPropertyBoolean(sb.getElement(), "disabled", !enabled); 
} 

//pass in your own TextBox when you construct the SB: 

TextBox tb = new TextBox(); 
SuggestBox sb = new SuggestBox(oracle, tb); 

//...and later disable the TextBox: 

tb.setEnabled(false); 
+0

感謝DrDro,會嘗試。 – Reddy 2010-06-24 09:38:05

+0

處理DOM元素工作正常。沒有嘗試第二個。 謝謝。 – Reddy 2010-06-24 13:24:33