AutoComplete
AutoComplete is a code completion library for Swing JTextComponents, with enhanced functionality available
for instances of RSyntaxTextArea.
AutoComplete is available under a modified BSD license.
Features
- A completion choices list that updates as the user types
- A "documentation" companion window for displaying documentation about the currently selected completion choice
- Parameter assistance (e.g. tabbing through function/method parameters, with tool tip assistance for each argument
and a possible list of valid variable completions for each)
Adding to Your Project
This library is available in the
Maven Central repository (com.fifesoft:autocomplete:XXX
).
SNAPSHOT builds of the in-development, unreleased version are hosted on
Sonatype.
Compiling
AutoComplete is built using Gradle. To compile the source, run all tests, and build the distribution jar,
simply run the following gradle command:
gradlew clean build --warning-mode all
Example Usage
The example below shows how to add code completion for simple keywords to
RSyntaxTextArea. For more examples, see the AutoCompleteDemo
submodule in this project.
import java.awt.*;
import javax.swing.*;
import org.fife.ui.autocomplete.*;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.fife.ui.rtextarea.RTextScrollPane;
public class AutoCompleteDemo extends JFrame {
public AutoCompleteDemo() {
JPanel contentPane = new JPanel(new BorderLayout());
RSyntaxTextArea textArea = new RSyntaxTextArea(20, 60);
textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
textArea.setCodeFoldingEnabled(true);
contentPane.add(new RTextScrollPane(textArea));
CompletionProvider provider = createCompletionProvider();
AutoCompletion ac = new AutoCompletion(provider);
ac.install(textArea);
setContentPane(contentPane);
setTitle("AutoComplete Demo");
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
setLocationRelativeTo(null);
}
private CompletionProvider createCompletionProvider() {
DefaultCompletionProvider provider = new DefaultCompletionProvider();
provider.addCompletion(new BasicCompletion(provider, "abstract"));
provider.addCompletion(new BasicCompletion(provider, "assert"));
provider.addCompletion(new BasicCompletion(provider, "break"));
provider.addCompletion(new BasicCompletion(provider, "case"));
provider.addCompletion(new BasicCompletion(provider, "transient"));
provider.addCompletion(new BasicCompletion(provider, "try"));
provider.addCompletion(new BasicCompletion(provider, "void"));
provider.addCompletion(new BasicCompletion(provider, "volatile"));
provider.addCompletion(new BasicCompletion(provider, "while"));
provider.addCompletion(new ShorthandCompletion(provider, "sysout",
"System.out.println(", "System.out.println("));
provider.addCompletion(new ShorthandCompletion(provider, "syserr",
"System.err.println(", "System.err.println("));
return provider;
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
try {
String laf = UIManager.getSystemLookAndFeelClassName();
UIManager.setLookAndFeel(laf);
} catch (Exception e) { }
new AutoCompleteDemo().setVisible(true);
});
}
}
Sister Projects
- RSyntaxTextArea provides syntax highlighting, code folding, and many other features out-of-the-box.
- RSTALanguageSupport - Code completion for RSTA for the following languages: Java, JavaScript, HTML, PHP, JSP, Perl, C, Unix Shell. Built on both RSTA and AutoComplete.
- SpellChecker - Adds squiggle-underline spell checking to RSyntaxTextArea.
- RSTAUI - Common dialogs needed by text editing applications: Find, Replace, Go to Line, File Properties.
Getting Help