How to set frame icon in JInternalFrame?

The following example illustrates how to set frame icon for JInternalFrame using setFrameIcon() method.
import javax.swing.*;
import java.awt.*;
class SetIconJInternalFrame extends JFrame
{
JInternalFrame f;
JDesktopPane p;

    public SetIconJInternalFrame()
    {
        createAndShowGUI();
    }
   
    private void createAndShowGUI()
    {
        setTitle("Set icon for JInternalFrame");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
       
        p=new JDesktopPane();
        p.setBackground(Color.GRAY);
       
        // title, resizable, closable, maximizable, iconifiable
        f=new JInternalFrame("Title",true,true,true,true);
        f.setSize(250,250);
        f.setVisible(true);
       
        // Set icon
        f.setFrameIcon(new ImageIcon("imageicon.png"));
       
        p.add(f);
       
        add(p);
       
        setSize(400,400);
        setVisible(true);
    }
   
    public static void main(String args[])
    {
        new SetIconJInternalFrame();
    }
}

In this way we can set icon using the setFrameIcon() method. I would be grateful to you, if you share this.
“What would life be if we had no courage to attempt anything?” - Vincent Van Gogh

No comments: