JFrameにアイコンを設定する

swingアプリケーションのウィンドウのアイコンを指定する

ImageIcon icon = new ImageIcon("icon.png");
frame.setIconImage(icon.getImage());

パスのセパレータは/じゃなくて\じゃないとだめな罠

ImageIcon icon = new ImageIcon("icon\\icon.png");
frame.setIconImage(icon.getImage());

この方がいいのかな?

ImageIcon icon = new ImageIcon("icon" + File.separator + "icon.png");
frame.setIconImage(icon.getImage());


pngやjpgが使用可能。せっかく作ったicoファイルは読んでくれなかった。
アイコンの設定方法は他にもあるらしいので今度調べる

以上。