0

Let's say I have this code here

String s=JOptionPane.showInputDialog("Type your age: ");

Then I run it, and for some reason the Pane doesn't show up. You need to minimize all windows, and there you'll find it! This doesn't happen always, and I saw it happening also to the tutorial guy, that is supposed to know why... So the question is:

How can I set the showInputDialog so it always comes to the front of the screen?

I reviewed the Java's API Documentation and couldn't find any parameter for the showInputDialog method that would set this (something like JOptionPane.showInputDialog("message", FRONT)). I also saw in this post that you can set the location with JDialog, but again, JDialog has a setLocation, that set's only the position (x,y) but not the placement among other windows.

This is a Code where it always happens:

public static void main (String [] args){
    Scanner input=new Scanner (System.in);
    System.out.println("Choose a form: \nSquare - 1\nCircle - 2\nRectangle - 3");
    int form=input.nextInt();
    switch (form){
    case 1:
        int height=Integer.parseInt(JOptionPane.showInputDialog("What is the height of the square?"));
    }
}
Community
  • 1
  • 1
Pablito
  • 197
  • 4
  • 16

1 Answers1

2

you can use JOptionPane.showInputDialog(rootPane, "Type your age: ");

change rootPane to your parent component.

ccc
  • 370
  • 5
  • 19
  • this code is works only with a GUI, and cannot use it when a console based program. when i run your example it works fine without any confusion. – ccc Sep 03 '15 at 06:10