Show dialog

Hi. I'm new to Idea plugins creation. I've looked up some examples but i cannot find something very simple. Can someone give me an example of a modal dialog box beeing shown from an action? All dialog examples i found are from classes that extends Configurable and a Panel is returned from public JComponent createComponent(). I would like to open a dialog from an Action class which does not have a createComponent.

public void actionPerformed(AnActionEvent event) {
.....
}

Thanks.

2 comments
Comment actions Permalink

Hello Cosmin,

Hi. I'm new to Idea plugins creation. I've looked up some examples but
i cannot find something very simple. Can someone give me an example of
a modal dialog box beeing shown from an action? All dialog examples i
found are from classes that extends Configurable and a Panel is
returned from public JComponent createComponent(). I would like to
open a dialog from an Action class which does not have a
createComponent.

public void actionPerformed(AnActionEvent event) {
....
}


You can simply show the dialog like you would do that in any other Swing
application. Alternatively, you can use IntelliJ IDEA's DialogWrapper class
which will give you many nice features like, for example, automatic remembering
of size and position. You can find many examples of DialogWrapper usage in
IDEA's bundled plugins and open-source third-party plugins:

http://www.google.com/codesearch?q=DialogWrapperintellij&hl=en&btnG=SearchCode

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Thanks. I've succeded using DialogWrapper:

public class TestDialog extends DialogWrapper {

public TestDialog() {
super(false);

init();
}

@Nullable
protected JComponent createCenterPanel() {
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(new JButton("Button"));

return panel;
}

This site also helps: http://www.piraya.nl/IDEAPlugins.html

Initialy i tried using a
DialogWrapper dlgWrapper = new DialogWrapper() {

@Nullable
protected JComponent createCenterPanel() {
//return a Panel
}
};
dlgWrapper.show();

but it seems that show does not call init() and init() is a key method to get the DialogWrapper to function.

0

Please sign in to leave a comment.