Icons used by JOptionPane

| ไอที | Java | 1443

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.

Icons used by JOptionPane
Icon description Java look and feel Windows look and feel
question The Java look and feel icon for dialogs that ask questions The Windows look and feel icon for dialogs that ask questions
information The Java look and feel icon for informational dialogs The Windows look and feel icon for informational dialogs
warning The Java look and feel icon for warning dialogs The Windows look and feel icon for warning dialogs
error The Java look and feel icon for error dialogs The Windows look and feel icon for error dialogs

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);
	}
}











comments