Displaying Error messages and using dialog boxes

how to use error messages and dialog boxes as of JOptionPane.showMessageDialog in java


Answer this question

Displaying Error messages and using dialog boxes

  • Roman Kiss

    Hi,

    You can use the static method showMessageDialog() of JOptionPane class to display the error messages. For the 'parentcomponent' parameter in this function, you can use "null". A simple app to display error message can be:

    import javax.swing.*;

    public class jopt {

    public static void main( String args[] ) {

    JOptionPane.showMessageDialog(null, "error", "error", JOptionPane.ERROR_MESSAGE);

    }

    }

    Here, fourth parameter( which can be ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE ) tells the the type of message to be displayed

    But, do keep in mind that each 'showXxxDialog()' method of JOptionPane blocks the current thread until the user's interaction is complete.

    thanks

    Prem



  • Displaying Error messages and using dialog boxes