为什么在我使用扫描仪时我的 JOptionPane 没有出现?

Why is my JOptionPane not appearing when I use a Scanner?

我已经缩小了我的问题范围:如果我使用扫描仪,JOptionPane 将不会出现。例如,这很好用:

public static void main(String[] args) {
    System.out.println("Before the dialog.");
    JOptionPane.showMessageDialog(null, "Please.");
    System.out.println("After the dialog.");
}

即使这样也行得通:

public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.println("Before the dialog.");
    JOptionPane.showMessageDialog(null, "Please.");
    System.out.println("After the dialog.");
}

但是,这不起作用:

public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int hi = butler.nextInt();
    System.out.println("Before the dialog.");
    JOptionPane.showMessageDialog(null, "Please.");
    System.out.println("After the dialog.");
}

在最后一个例子中,程序等待输入,然后显示"Before the dialog."之后,程序似乎卡住了。

我尝试在创建对话框之前关闭扫描仪,但没有效果。

它确实在 Scanner 读取输入后出现。它只是没有作为顶级 window 出现。请参阅 JOptionPane won't show its dialog on top of other windows 了解如何解决此问题。