/** * Gets the strict completion property. * * @return the value of strict completion property. * * @see #setStrictCompletion(boolean) */ public boolean isStrictCompletion() { return getAutoCompletion().isStrictCompletion(); }
protected void setText(String text) { try { // remove all text and insert the completed string if (isStrictCompletion()) { super.remove(0, getLength()); super.insertString(0, text, null); } else { String existingText = super.getText(0, getLength()); int matchIndex = existingText.length() <= text.length() ? existingText.length() : text.length(); // try to find a match for (int i = 0; i < existingText.length(); i++) { if (!existingText.substring(0, matchIndex).equalsIgnoreCase(text.substring(0, matchIndex))) { matchIndex--; } } // remove the no-match part and complete with the one in Searchable super.remove(matchIndex, getLength() - matchIndex); super.insertString(matchIndex, text.substring(matchIndex), null); } } catch (BadLocationException e) { throw new RuntimeException(e.toString()); } } }