setEditable(false)
및 setForceSelection(true)
을 사용하고 클래스를 확장하면 직접 (위젯에서 키 누르기를 관찰하여)이를 수행 할 수 있습니다.
첫째, 서브 클래스 :
package net.binarymuse.gwt.gxt.client;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.KeyListener;
import com.extjs.gxt.ui.client.widget.form.SimpleComboBox;
public class MySimpleComboBox<T extends String> extends SimpleComboBox<T> {
public MySimpleComboBox() {
super();
this.addKeyListener(new KeyListener(){
@Override
public void componentKeyDown(ComponentEvent event)
{
// Get a reference to the combobox in question
MySimpleComboBox<T> combo = MySimpleComboBox.this;
// Get the character that has been pressed
String sChar = String.valueOf((char) event.getKeyCode());
// TODO - add some checking here to make sure the character is
// one we actually want to process
// Make sure we have items in the store to iterate
int numItems = combo.getStore().getCount();
if(numItems == 0)
return;
// Check each item in the store to see if it starts with our character
for(int i = 0; i < numItems; i++)
{
String value = combo.getStore().getAt(i).getValue();
// If it does, select it and return
if(value.startsWith(sChar) || value.startsWith(sChar.toUpperCase()))
{
MySimpleComboBox.this.setSimpleValue((T) value);
return;
}
}
}
});
}
}
그리고 시험 :
package net.binarymuse.gwt.gxt.client;
import com.extjs.gxt.ui.client.widget.form.SimpleComboBox;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;
public class GxtSandbox implements EntryPoint {
public void onModuleLoad() {
SimpleComboBox<String> box = new MySimpleComboBox<String>();
box.add("One");
box.add("Two");
box.add("Three");
box.setEditable(false);
box.setForceSelection(true);
RootPanel.get().add(box);
}
}
콤보 상자 포커스를 부여하고 목록에서 "2"를 선택해야한다 "T"를 누르면.
마찬가지로 클래스는 항상 문자로 시작하는 목록의 첫 번째 항목을 선택합니다. 그러나 목록에서 다음 항목을 선택하도록 수정하는 것은 어렵지 않습니다 ("실제"콤보 상자와 마찬가지로).
나는 분명치 않다. 나는 모든 것을 혼자 할 수 있다는 것을 알고 있으며, 적절한 옵션으로 이것을 수행 할 수있는 내장 된 방법이 있어야한다고 생각했습니다. 어쩌면 거기 있지 않을까요? –
나는 이해가 안가는 것을 본다. "당신이 생각할"수있는 옵션은이 동작을 호출하지 않습니다. 버그 일 수도 있고 좋은 기능 요청 일 수도 있습니다. –
그래, 그게 내가 생각한거야.하지만 내가 방금 뭔가를 놓쳤 으면 좋겠다. 감사. –