@Override
 public void setSelectedIndex(int ind) {
   super.setSelectedIndex(ind);
   editor.setText(getItemAt(ind).toString());
   editor.setSelectionEnd(caretPos + editor.getText().length());
   editor.moveCaretPosition(caretPos);
 }
  private int selectCompletionRemoveText(
      final CompletionResult result, boolean selectReplacedText) {
    int pos = myPathTextField.getCaretPosition();

    if (result.myToComplete.size() > 0 && selectReplacedText) {
      myPathTextField.setCaretPosition(myPathTextField.getText().length());
      myPathTextField.moveCaretPosition(pos);
    }

    return pos;
  }
Example #3
0
  public void keyReleased(KeyEvent e) {
    char ch = e.getKeyChar();
    if (ch == KeyEvent.CHAR_UNDEFINED || Character.isISOControl(ch)) return;
    int pos = m_editor.getCaretPosition();
    String str = m_editor.getText();
    if (str.length() == 0) return;

    for (int k = 0; k < m_comboBox.getItemCount(); k++) {
      String item = m_comboBox.getItemAt(k).toString();
      if (item.startsWith(str)) {
        m_editor.setText(item);
        m_editor.setCaretPosition(item.length());
        m_editor.moveCaretPosition(pos);
        m_comboBox.setSelectedItem(item);
        break;
      }
    }
  }
 /**
  * Sets list index based on editor's text.
  *
  * @return true if matching item was found on the list
  */
 private boolean setSelectedByEditor() {
   String editorText = editorField.getText().toUpperCase();
   if (editorText.length() == 0) {
     return false;
   }
   int pos = editorField.getCaretPosition();
   boolean found = false;
   for (int i = 0; i < getItemCount() && !found; i++) {
     String item = getItemAt(i).toString();
     if (item.toUpperCase().startsWith(editorText)) {
       editorField.setText(item);
       editorField.setCaretPosition(item.length());
       editorField.moveCaretPosition(pos);
       moveCaretInSelection = false;
       setSelectedIndex(i);
       moveCaretInSelection = true;
       found = true;
     }
   }
   return found;
 }