Icons used by JOptionPane
Icons used by JOptionPane
Using JOptionPane, you can quickly create and customize several different kinds of dialogs. JOptionPane provides support for laying out standard dialogs, providing icons, specifying the dialog title and text, and customizing the button text. Other features allow you to customize the components the dialog displays and specify where the dialog should appear onscreen. You can even specify that an option pane put itself into an internal frame (JInternalFrame) instead of a JDialog.When you create a JOptionPane, look-and-feel-specific code adds components to the JOptionPane and determines the layout of those components.
JOptionPane's icon support lets you easily specify which icon the dialog displays. You can use a custom icon, no icon at all, or any one of four standard JOptionPane icons (question, information, warning, and error). Each look and feel has its own versions of the four standard icons. The following figure shows the icons used in the Java (and Windows) look and feel.
Icon description | Java look and feel | Windows look and feel |
---|---|---|
question | ![]() | ![]() |
information | ![]() | ![]() |
warning | ![]() | ![]() |
error | ![]() | ![]() |
How to use
import javax.swing.JFrame; import javax.swing.JOptionPane; public class JavaCodeExam { public static void main(String[] args) throws Exception { JFrame frame = new JFrame(); JOptionPane.showMessageDialog(frame, "ERROR_MESSAGE", " Test Message ", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(frame, "INFORMATION_MESSAGE", " Test Message ", JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(frame, "PLAIN_MESSAGE", " Test Message ", JOptionPane.PLAIN_MESSAGE); JOptionPane.showMessageDialog(frame, "QUESTION_MESSAGE", " Test Message ", JOptionPane.QUESTION_MESSAGE); JOptionPane.showMessageDialog(frame, "WARNING_MESSAGE", " Test Message ", JOptionPane.WARNING_MESSAGE); } }




