Close "IDialogHandler" programmatically

I think this is a selly question but I really can’t find an answer.
I have a class that implements IDialogHandler:

public class ClassDiagramStereo implements IDialogHandler {

    JButton OkButton = new JButton("Ok");
	JTextField stereoTextField = new JTextField();

    public Component getComponent() {
        JPanel mainPane = new JPanel();

        mainPane.setLayout(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.insets = new Insets(2, 2, 2, 2);

        //Ok Button
		mainPane.add(OkButton, gbc);
        mainPane.add(stereoTextField, gbc);

        // Ok Button
        OkButton.addActionListener(e -> {
          //Do some thing...
		  //Then close the window

        return mainPane;

    public void prepare(IDialog dialog) {
        dialog.setTitle("MDE - Select PDM");

    public void shown() {

    public boolean canClosed() {
        return true;

    public string getStereo(){
        return stereoTextField.getText();


When pressing the button “Ok” i want to do some work then the window closes.

i call the ClassDiagramStereo handler from another handler like this:

ViewManager vm = ApplicationManager.instance().getViewManager();
ClassDiagramStereo classDiagramStereo= new ClassDiagramStereo();
Stereo = classDiagramStereo.getStereo();

My question is how I can close programmatically an “IDialogHandler” ?

Thank you

The instance of IDialog you get on the prepare(IDialog dialog) method has a close() method that you can use (see the APU here).

Just remember to invoke the dialog on its own thread.

1 Like

This is how i managed to close the window (Dialog)

// Ok Button
OkButton.addActionListener(e -> {
    //Do some thing...
    Component component = (Component) e.getSource();
    JDialog dialog = (JDialog) SwingUtilities.getRoot(component);