Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>By using <code>setEditable(false)</code> and <code>setForceSelection(true)</code> and extending the class, you can accomplish this yourself (by watching for key presses on the widget).</p> <p>First, the subclass:</p> <pre><code>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&lt;T extends String&gt; extends SimpleComboBox&lt;T&gt; { public MySimpleComboBox() { super(); this.addKeyListener(new KeyListener(){ @Override public void componentKeyDown(ComponentEvent event) { // Get a reference to the combobox in question MySimpleComboBox&lt;T&gt; 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 &lt; 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; } } } }); } } </code></pre> <p>And the test:</p> <pre><code>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&lt;String&gt; box = new MySimpleComboBox&lt;String&gt;(); box.add("One"); box.add("Two"); box.add("Three"); box.setEditable(false); box.setForceSelection(true); RootPanel.get().add(box); } } </code></pre> <p>Giving the combo box focus and pressing "T" should select "Two" in the list.</p> <p>As is, the class always selects the first item in the list that starts with the character; however, it would not be difficult to modify it to make it select the next item in the list (as is typical with "real" combo boxes).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload