如何打开警告/信息/错误对话框?

jav*_*red 33 java swing joptionpane

如何打开警告/信息/错误对话框?

我需要带有"确定"按钮和"红叉"图像的标准错误对话框.即模拟org.eclipse.jface.dialogs.MessageDialog.openError()

Jon*_*nas 55

请参见如何制作对话框.

您可以使用:

JOptionPane.showMessageDialog(frame, "Eggs are not supposed to be green.");
Run Code Online (Sandbox Code Playgroud)

您还可以将符号更改为错误消息或警告.例如,请参阅JOptionPane功能.

  • 确保您处理了框架,或将 null 作为框架传递。如果你不这样做,它可以保持你的进程打开。 (2认同)

小智 17

import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class ErrorDialog {

  public static void main(String argv[]) {
    String message = "\"The Comedy of Errors\"\n"
        + "is considered by many scholars to be\n"
        + "the first play Shakespeare wrote";
    JOptionPane.showMessageDialog(new JFrame(), message, "Dialog",
        JOptionPane.ERROR_MESSAGE);
  }
}
Run Code Online (Sandbox Code Playgroud)


Hei*_*bug 9

JOptionPane.showOptionDialog
JOptionPane.showMessageDialog
....
Run Code Online (Sandbox Code Playgroud)

看看本教程如何制作对话框.