---
category: swing
folder: InternalFrameTitleIcon
title: JInternalFrameのタイトルバーに表示されるアイコンを変更する
tags: [JInternalFrame, JDesktopPane, Icon]
author: aterai
pubdate: 2014-12-22T00:07:25+09:00
description: JInternalFrameのタイトルバー左上隅に表示されるアイコンを各JInternalFrame毎に設定します。
image: https://lh3.googleusercontent.com/-rFS_L31nMfg/VJbgMqwW0UI/AAAAAAAANtY/z1JvoM0odco/s800/InternalFrameTitleIcon.png
---
* 概要 [#summary]
`JInternalFrame`のタイトルバー左上隅に表示されるアイコンを各`JInternalFrame`毎に設定します。

#download(https://lh3.googleusercontent.com/-rFS_L31nMfg/VJbgMqwW0UI/AAAAAAAANtY/z1JvoM0odco/s800/InternalFrameTitleIcon.png)

* サンプルコード [#sourcecode]
#code(link){{
int idx = 0;
for (Color c: Arrays.asList(Color.RED, Color.GREEN, Color.BLUE)) {
  String s = String.format("Document #%s", ++idx);
  JInternalFrame f = new JInternalFrame(s, true, true, true, true);
  desktop.add(f);
  f.setFrameIcon(new ColorIcon(c));
  f.setSize(240, 120);
  f.setLocation(10 + 20 * idx, 20 * idx);
  f.setVisible(true);
}
}}

* 解説 [#explanation]
上記のサンプルでは、`JInternalFrame#setFrameIcon(Icon)`を使用して、それぞれ違う色をもつサイズ`16x16`のアイコンを設定しています。

- `WindowsLookAndFeel`
-- アイコン化したとき、`JInternalFrame#setFrameIcon(Icon)`で設定した`Icon`を拡大した画像が`JInternalFrame.JDesktopIcon`に使用される
- `MotifLookAndFeel`
-- `JInternalFrame#setFrameIcon(Icon)`で設定したアイコンは表示されない(デフォルトアイコンも表示しない)

* 参考リンク [#reference]
- [https://docs.oracle.com/javase/jp/8/docs/api/javax/swing/JInternalFrame.html#setFrameIcon-javax.swing.Icon- JInternalFrame#setFrameIcon(Icon) (Java Platform SE 8)]

* コメント [#comment]
#comment
#comment