Use ChooseByNamePopup inside custom form/dialog


Hi, is there any way to have some textfield with autocomplete list like the one used in the popup for searching symbols/classes/files etc?

I know we can create a popup like that using "ChooseByNamePopup" but that will create and invoke just that, a popup with just one textfield, I need that textfield inside another form/dialog, is that possible? do you have any recommendation?

Thanks !!


There's also ChooseByNamePanel, a control with a text field and a list of the matching results, used e.g. in Java exception breakpoints to choose a class. Or you could try to extend ChooseByNameBase in any way you like, but beware it's quite a private API and might be changed.


Thanks Peter! I think that could work


If you need just a text field, you might also consider not using ChooseByName, but instead having a TextFieldWithAutoCompletion (or a generic EditorTextField) and providing the completion variants there (via TextCompletionProvider or a more generic CompletionContributor).


Sadly I was not able to use any of those solutions.

With TextFieldWithAutoCompletion I'm getting the error: 

java.lang.AssertionError: Completion should not be invoked inside write action

(my dialog is executed inside an intention Action)

And using ChooseByNamePanel is not showing any autocomplete (it shows the textfield and an empty list component below, but no autocomplete):

Maybe I'm using it wrong, I'm just testing something simple:


protected JComponent createCenterPanel() {

chooseByNamePanel = new ChooseByNamePanel(project, new GotoClassModel2(project), "", false, null);
chooseByNamePanel.invoke(new ChooseByNamePopupComponent.Callback() {
public void elementChosen(Object element) {

}, ModalityState.stateForComponent(mainPanel), false);




You shouldn't show dialogs inside write actions, but you can override com.intellij.codeInsight.intention.IntentionAction#startInWriteAction

Please try using ModalityState.stateForComponent(getRootPane())


using startInWriteAction did the trick, TextFieldWithAutoCompletion works fine now.

And ChooseByNamePanel is showing the autocompletion but when I select some item from the autocomplete list is not put inside the textfield, and also I can see there is some rectangle, empty, drawed on the screen under my Dialog, I think could be related with some problem with the invoke method inside the dialog or something like that (I'm using getRootPane() too).

I can use TextFieldWithAutoCompletion, but would be nice to make it work the ChooseByNamePanel too if you know what could be causing that issue.

Thanks Peter for your help!


Unfortunately I can't tell what the problem with ChooseByNamePanel could be right now, you'd need some debugging. You could try to debug some of its usages in intellij-community source and see where they differ from your code.


Please sign in to leave a comment.