2

I want to make a simple Yes/No-Dialog. Quite simple actually of course:

 int i = JOptionPane.showConfirmDialog(c, "Do you really want to delete file",
         "JfD", JOptionPane.YES_NO_OPTION);

But now I want to have it position somewhere else than the center of the screen.

I tried to use another parent component than "this":

Frame c = new Frame();
c.setBounds(200, 200, 100, 100);
int i = JOptionPane.showConfirmDialog(c, "Do you really want to delete
        file", "JfD", JOptionPane.YES_NO_OPTION);

This did not work. I also tried to create a new dialog:

   final JOptionPane pane = new JOptionPane("Do you really want to delete 
         this file?", JOptionPane.PLAIN_MESSAGE, JOptionPane.YES_NO_OPTION);
   final JDialog d = pane.createDialog("JavaFunctionsDatabase3");
   d.setLocation(frameX+120, frameY+80);
   d.setVisible(true);
   int i = pane.getValue();

This positioned the dialog right, but I cannot get the right input, because here the dialog does not "wait" for the users input - so I get just an error from pane.getvalue(); bc it does not have any then.

I hope anybody has a solution, either to set the bounds of the first dialogs or to have the second one "wait" (that is alss needed because the following actions depend on the users choice).

Thank you very much for any help!

wittn
  • 298
  • 5
  • 16
  • I think there is something wrong with your context of running this program, since by calling `d.setVisible(true);` a dialog always creates a **wait** until one of those YES or NO options is clicked and then `int i = pane.getValue();` is being executed. You can verify this by debugging your snippet code in a simple java class. – STaefi Dec 05 '18 at 13:46
  • @STaefi Yes. Thank you. I tried it again...must have had the order wrong or something. It is working now, so thanks! – wittn Dec 05 '18 at 15:46

0 Answers0