1

i want to open new JDialog box inside JDialog box. so i have used that code to prevent to come on ancestor JFrame but i am facing the problem to open new JDialog box in previous JDialog box. please give me the solution to get rid of this problem.

Here is the code :-

            TestbedWorkflow tbwf = new TestbedWorkflow();
            JDialog dialog = new JDialog();
            Dimension s = SOAStreamer.getSOAStreamerObj().getContentPanel().getSize();
            dialog.setSize(s);
            dialog.setTitle("TestBed Workflow Design");
            dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
            dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
            tbwf.setSize(s);
            dialog.add(tbwf);
            tbwf.updateUI();
            dialog.setVisible(true);

TestbedWorkflow is JFrame which i have added in to JDialog box.now i want to open new JDialog box.

thanks in advance

user591790
  • 545
  • 2
  • 15
  • 33

1 Answers1

1

The example below opens an arbitrary number of dialogs in an APPLICATION_MODAL hierarchy; only the most recent is operable. As an alternative, consider a modeless dialog, illustrated here.

Update: The revised example below shows the hierarchy depth in the dialog title and eliminates a spurious subclass.

import java.awt.Dialog;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;

/**
* @see https://stackoverflow.com/a/12301243/230513
*/
public class DialogTest {

    private static int index;

    static class OpenAction extends AbstractAction {

        public OpenAction() {
            super("Open");
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            JDialog jd = new JDialog();
            jd.setTitle("D" + String.valueOf(++index));
            jd.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
            jd.add(new JButton(new OpenAction()));
            jd.pack();
            jd.setLocationRelativeTo(null);
            jd.setVisible(true);
        }
    }

    private void display() {
        JFrame f = new JFrame("DialogTest");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add(new JButton(new OpenAction()));
        f.pack();
        f.setLocationRelativeTo(null);
        f.setVisible(true);
    }

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new DialogTest().display();
            }
        });
    }
}
Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045