0

I want to make JFrame like JDialog box so user can not go outside the JFrame or parent JFrame. how can i make this. please help me.

This is my code:-

    TestBedForm n = new TestBedForm();
    JDialog dialog = new JDialog();
    dialog.setSize(n.getSize());
    dialog.setTitle("Design");
    dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
    dialog.add(n);
    dialog.setVisible(true);

Here TestBedForm is JFrame and now i want to open this as JDialog box so what is wrong with this code. can somebody help me.

thanks in advance

user591790
  • 545
  • 2
  • 15
  • 33

1 Answers1

1

You cannot add a JFrame into a Container. You will get RuntimeError. Try dialog.add(n.getContentPane()); instead of dialog.add(n);

basiljames
  • 4,777
  • 4
  • 24
  • 41