私は障害のある人のためのDisplaykeyboardに取り組んでいます。私は自動単語補完機能を追加しようと考えています。 私が必要とするように働くoracleの例が見つかりました。その別の例:TextAreaDemo問題は、私は本当に検索アルゴリズムを理解していないと問題は、私はarraylistに検索アルゴリズムが正しく動作を停止するいくつかの単語を追加するときです。自動補完機能Java
String prefix = content.substring(w + 1).toLowerCase();
int n = Collections.binarySearch(words, prefix);
if (n < 0 && -n <= words.size()) {
String match = words.get(-n - 1);
if (match.startsWith(prefix)) {
// A completion is found
String completion = match.substring(pos - w);
// We cannot modify Document from within notification,
// so we submit a task that does the change later
SwingUtilities.invokeLater(
new CompletionTask(completion, pos + 1));
}
} else {
// Nothing found
mode = Mode.INSERT;
}
どのような単語でも動作するようにサンプルを変更する方法はありますか?
を例へのリンクがhttp://docs.oracle.com/javase/tutorial/uiswing/components/textarea.html – QFireball
'binarySearch'がソートさに依存していますあなたは単語を追加した後にあなたのリストを再度ソートしないと思いますか? –
リストは静的なので、これは本当に必要なものではありません – QFireball