如何在swing中打開警告/信息/錯誤對話框?如何在swing中打開警告/信息/錯誤對話框?
我需要帶有「確定」按鈕和「紅十字」圖像的標準錯誤對話框。 也就是說org.eclipse.jface.dialogs.MessageDialog.openError()的模擬
如何在swing中打開警告/信息/錯誤對話框?如何在swing中打開警告/信息/錯誤對話框?
我需要帶有「確定」按鈕和「紅十字」圖像的標準錯誤對話框。 也就是說org.eclipse.jface.dialogs.MessageDialog.openError()的模擬
您可以使用:
JOptionPane.showMessageDialog(frame, "Eggs are not supposed to be green.");
而且你還可以更改符號的錯誤消息或警告。例如參見JOptionPane Features。
JOptionPane.showOptionDialog
JOptionPane.showMessageDialog
....
看看這個tutorial關於如何進行對話。
謝謝,這個工程 – javapowered 2011-06-07 19:20:43
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);
}
}
只是補充:這是一種顯而易見的,但你可以使用靜態導入給你一隻手,像這樣:
import static javax.swing.JOptionPane.*;
public class SimpleDialog(){
public static void main(String argv[]) {
showMessageDialog(null, "Message", "Title", ERROR_MESSAGE);
}
}
確保你處置框架,或傳遞null作爲框架。如果你不這樣做,它可以保持你的過程開放。 – ScrappyDev 2017-02-24 15:47:16