The first argument is the component over which the dialog is to appear.
The second argument is the message to be displayed
The third argument displays the text to appear in the titlebar of the dialog
The fourth argument is the message type - as shown below
Dialog Type |
Icon |
Description |
|
JOptionPane.ERROR_MESSAGE |
A Dash |
Indicates an error to the user |
|
JOptionPane.INFORMATION_MESSAGE |
An i |
Display an informational message |
|
JOptionPane.WARNING_MESSAGE |
Exclamation Mark |
Warns user of a potential problem |
|
JOptionPane.QUESTION_MESSAGE |
Question Mark |
Poses a question to the user |
|
JOptionPane.PLAIN_MESSAGE |
No Icon |
Contains a message with no icon |





import javax.swing.*;
class TextArea
{
public static void main (String []args)
{
String output = "Rating\tFrequency\n";
for (int i = 0; i < 10; i++)
output = output + i + "\t" + i+1 + "\n";
JTextArea outputArea = new JTextArea();
outputArea.setText(output);
JOptionPane.showMessageDialog (null, outputArea, "Example", JOptionPane.INFORMATION_MESSAGE);
}
}
