Search code examples
intellij-ideaintellij-plugin

intellij plugin development show input dialog with multiple text boxes


I'm creating intelliJ plugin and registering my action , inside my action i want to show an input dialog with multiple text boxes, how do I do that ? I have an example of showing only one text box -

 String txt= Messages.showInputDialog(project, "What is your name?", 
                                     "Input your name", Messages.getQuestionIcon());

Solution

  • Create a new GUI Form (form + class). Class should extend DialogWrapper and override methods.

    Inside createCenterPanel() return your root JPanel. You can set any default values, add event listeners to text box, etc., before returning JPanel.

    Implement an Action interface where you want to get the value when OK button is clicked. Pass this action to your form class.

    getOKAction() should return this action.

    Following code is from a plugin i'm currently working on. Hopefully this will give you some idea but will have to adapt it to your need.

    public class ReleaseNoteDialog extends DialogWrapper implements Action {
        private JTextArea txtReleaseNote;
        private JPanel panelWrapper;
    
        .......
        protected JComponent createCenterPanel() {
            ......
            return panelWrapper;
        }
        ......
        @Override
        protected Action getOKAction() {
             return this;
        }
        .......
       @Override
       public void actionPerformed(ActionEvent e) {
            // save value to project state
            super.doOKAction();
       }