How to open warning/information/error dialog in Swing?
I need standard error dialog with "Ok" button and "red cross" image. I.e. analog of org.eclipse.jface.dialogs.MessageDialog.openError()
JDialog is a part Java swing package. The main purpose of the dialog is to add components to it. JDialog can be customized according to user need . Constructor of the class are: JDialog() : creates an empty dialog without any title or any specified owner.
showMessageDialog() − To show the message alert. JOptionPane. WARNING_MESSAGE − To mark the alert message as warning.
See How to Make Dialogs.
You can use:
JOptionPane.showMessageDialog(frame, "Eggs are not supposed to be green.");
And you can also change the symbol to an error message or an warning. E.g see JOptionPane Features.
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); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With