JOptionPane showMessageDialog with Icon (Another Way to get ImageIcon)

showMessageDialog( Component parent, Object message, String title, int messageType, Icon icon)

The first argument is the parent for the dialog that is used to position the dialog.The second argument specifies what is to be displayed in addition to the default OK button. Third argument specifies by the title. The fourth argument specifies messageType. if you except that the icon is what you pass as the fifth argument. you may just need to get the file path of specified file With the help of getResource() method, you can extract the file path easily.





Program Source

import javax.swing.JOptionPane;
import javax.swing.ImageIcon;

public class Javaapp{
   public static void main(String[] args){

       ImageIcon icon = new ImageIcon(Javaapp.class.getResource("WLive48x48.png"));

Leave a Comment