bobbylight / AutoComplete

A code completion library for Swing text components, with special support for RSyntaxTextArea.
BSD 3-Clause "New" or "Revised" License
166 stars 55 forks source link

why it is not working ,i use the example "AutoCompleteDemo" #76

Closed dreamcatcher-cx closed 4 years ago

dreamcatcher-cx commented 4 years ago

i use the example given by the offical. but when i type “a",it can't auto complete automatically.what key do i need to press?

bobbylight commented 4 years ago

By default the auto-completion popup won't display unless the user types Ctrl+Space. If you want to make the window popup from different characters just being typed you have to do a little extra legwork. You have to enable "auto-activation" on the AutoCompletion instance, as well as set what characters should auto-trigger the popup in the CompletionProvider. For example:

AutoCompletion ac = new AutoCompletion(provider);
ac.install(textArea);
ac.setShowDescWindow(true);
ac.setAutoCompleteEnabled(true);
ac.setAutoActivationEnabled(true);
ac.setAutoCompleteSingleChoices(false);
ac.setAutoActivationDelay(500); // Number of milliseconds to debounce the popup window.  Must be >= 0

...

// The magic is setAutoActivationRules(boolean letters, String otherChars)
// e.g. setAutoActivationRules(true, null) will trigger the popup on a-z or A-Z pressed
// setAutoActivationRules(null, ".") will trigger the popup when "." is pressed, e.g. for method completions.
DefaultCompletionProvider provider = new DefaultCompletionProvider();
provider.setAutoActivationRules(true, null);
provider.addCompletion(new ShorthandCompletion(provider, "sysout","System.out.println(", "System.out.println("));
provider.addCompletion(new ShorthandCompletion(provider, "syserr", "System.err.println(", "System.err.println("));