Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing an Alert Dialog in Java Swing

Tags:

java

swing

I want to giving an alert when there is an exception, like in code:

try
{
    //the code here
}
catch(Exception e)
{
    //show an alert dialog here
}

An example or a code snippet is what I need.

like image 876
Ved Avatar asked Dec 03 '13 11:12

Ved


People also ask

How do I call a dialog box in Java?

Message dialogs are created with the JOptionPane. showMessageDialog() method. We call the static showMessageDialog() method of the JOptionPane class to create a message dialog. We provide the dialog's parent, message text, title, and message type.


1 Answers

You can use JOptionPane.showMessageDialog with WARNING_MESSAGE :

JOptionPane.showMessageDialog(yourFrame,
    "WARNING.",
    "Warning",
    JOptionPane.WARNING_MESSAGE);

More infos about how to make dialogs here.

like image 178
user2336315 Avatar answered Nov 02 '22 13:11

user2336315