• 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

概要

JInternalFrameのタイトルバー左上隅に表示されるアイコンを各JInternalFrame毎に設定します。

サンプルコード

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);
}
View in GitHub: Java, Kotlin

解説

上記のサンプルでは、JInternalFrame#setFrameIcon(Icon)メソッドを使用して、各JInternalFrameに異なる色の16x16アイコンを設定しています。

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

参考リンク

コメント