Provide Auto-complete in a text field(JTextField)

I have created a custom dialog(JDialog) with two JTextField and I want to provide auto complete feature in those text fields
Any suggestions how to do that?

12 comments
Comment actions Permalink

see com.intellij.ui.TextFieldWithAutoCompletion

0
Comment actions Permalink

Thanks Yann for replying.
I m new to idea's UI, So can you please explain,
How can I use com.intellij.ui.TextFieldWithAutoCompletion instead of JTextField in JDialog ?
As far as I have tried JDialog requires javax.swing components.

0
Comment actions Permalink

What is the problem exactly? It inherits from JComponent so it"s a Swing component you can use as JTextField.

0
Comment actions Permalink

If I use it, it does not show the dialog and fails with the following exception :

Argument for @NotNull parameter 'project' of com/intellij/psi/PsiDocumentManager.getInstance must not be null
java.lang.IllegalArgumentException: Argument for @NotNull parameter 'project' of com/intellij/psi/PsiDocumentManager.getInstance must not be null
at com.intellij.psi.PsiDocumentManager.getInstance(PsiDocumentManager.java)
 at com.intellij.ui.TextFieldWithAutoCompletionContributor.installCompletion(TextFieldWithAutoCompletionContributor.java:55)
 at com.intellij.ui.TextFieldWithAutoCompletion.<init>(TextFieldWithAutoCompletion.java:68)
 at com.intellij.ui.TextFieldWithAutoCompletion.<init>(TextFieldWithAutoCompletion.java:56)

0
Comment actions Permalink

Argument for @NotNull parameter 'project' of com/intellij/psi/PsiDocumentManager.getInstance must not be null

you must pass in Project parameter

0
Comment actions Permalink
This is my dialog constructor and the exception says: error is in the first line of the constructor.
I debugged it and saw that the project was not null but still gives me the same exception.
  
Argument for @NotNull parameter 'project' of com/intellij/psi/PsiDocumentManager.getInstance must not be null 
java.lang.IllegalArgumentException: Argument for @NotNull parameter 'project' of com/intellij/psi/PsiDocumentManager.getInstance must not be null
 
at com.intellij.psi.PsiDocumentManager.getInstance(PsiDocumentManager.java)
at com.intellij.ui.TextFieldWithAutoCompletionContributor.installCompletion(TextFieldWithAutoCompletionContributor.java:55)
at com.intellij.ui.TextFieldWithAutoCompletion.<init>(TextFieldWithAutoCompletion.java:68)
at com.intellij.ui.TextFieldWithAutoCompletion.<init>(TextFieldWithAutoCompletion.java:56)
  
public ExtractConceptDialog(Project project) {
        this.textField1 = new com.intellij.ui.TextFieldWithAutoCompletion(project,new TextFieldWithAutoCompletionListProvider(Arrays.asList("HEHEHEH","AAAAA","BBBBB","Step")) {
            @Nullable
            @Override
            protected
Icon getIcon(Object o) {
                return null;
            
}

            @NotNull
            @Override
            protected
String getLookupString(Object o) {
                return "Lookup";
            
}

            @Nullable
            @Override
            protected
String getTailText(Object o) {
                return "Tail";
            
}

            @Nullable
            @Override
            protected
String getTypeText(Object o) {
                return "Type";
            
}

            @Override
            public int compare
(Object o, Object t1) {
                return 0;
            
}
        },true,"");
        
setContentPane(contentPane);
        
setModal(true);
    
}
0
Comment actions Permalink

how do you call

ExtractConceptDialog(Project project)
0
Comment actions Permalink
 
final ExtractConceptDialog form = new ExtractConceptDialog(editor.getProject());
form.setData(steps, getConceptNames());
final
DialogBuilder builder = new DialogBuilder(editor.getProject());
builder.setCenterPanel(form.getRootPane());
builder.setTitle("Extract");
builder.removeAllActions();
builder.addCancelAction();
builder.addOkAction();
builder.show();
0
Comment actions Permalink

show the whole stacktrace of exception, please

0
Comment actions Permalink

Argument for @NotNull parameter 'project' of com/intellij/psi/PsiDocumentManager.getInstance must not be null
java.lang.IllegalArgumentException: Argument for @NotNull parameter 'project' of com/intellij/psi/PsiDocumentManager.getInstance must not be null
 at com.intellij.psi.PsiDocumentManager.getInstance(PsiDocumentManager.java)
 at com.intellij.ui.TextFieldWithAutoCompletionContributor.installCompletion(TextFieldWithAutoCompletionContributor.java:55)
 at com.intellij.ui.TextFieldWithAutoCompletion.<init>(TextFieldWithAutoCompletion.java:68)
 at com.intellij.ui.TextFieldWithAutoCompletion.<init>(TextFieldWithAutoCompletion.java:56)
 at com.thoughtworks.gauge.extract.ExtractConceptDialog.$$$setupUI$$$(ExtractConceptDialog.java)
 at com.thoughtworks.gauge.extract.ExtractConceptDialog.<init>(ExtractConceptDialog.java:19)
 at com.thoughtworks.gauge.extract.ExtractConceptInfoCollector.getAllInfo(ExtractConceptInfoCollector.java:29)
 at com.thoughtworks.gauge.extract.ExtractConceptHandler.invoke(ExtractConceptHandler.java:29)
 at com.intellij.refactoring.actions.BaseRefactoringAction.actionPerformed(BaseRefactoringAction.java:122)
 at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher$3.performAction(IdeKeyEventDispatcher.java:614)
 at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.java:663)
 at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.d(IdeKeyEventDispatcher.java:513)
 at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.dispatchKeyEvent(IdeKeyEventDispatcher.java:211)
 at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:546)
 at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:384)
 at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
 at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
 at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
 at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

0
Comment actions Permalink

try using passed in Project parameter from com.intellij.refactoring.RefactoringActionHandler#invoke(com.intellij.openapi.project.Project, com.intellij.openapi.editor.Editor, com.intellij.psi.PsiFile, com.intellij.openapi.actionSystem.DataContext)

0
Comment actions Permalink

Got it working.......
I was missing the option "Custom create" for the auto complete field in the GUI form, that was why it was getting null as project
Now I m initializing the field with the project and it works....
Thanks Yann for helping

0

Please sign in to leave a comment.