• 追加された行はこの色です。
  • 削除された行はこの色です。
TITLE:DesktopManagerでアイコンの再配置
#navi(../)
#tags()
RIGHT:Posted by &author(aterai); at 2007-01-15
*DesktopManagerでアイコンの再配置 [#pe96a24f]
JDesktopPaneのサイズが変更されたとき、アイコン化しているJInternalFrameの再配置を行います。[http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4765256 Bug ID: 4765256 REGRESSION: Icons in JDesktopPane not repositioned when pane is resized]からソースコードの大部分を引用しています。
---
category: swing
folder: RelocatedIcon
title: DesktopManagerでアイコンの再配置
tags: [DesktopManager, JDesktopPane, JInternalFrame]
author: aterai
pubdate: 2007-01-15T12:27:58+09:00
description: JDesktopPaneのサイズが変更されたとき、アイコン化しているJInternalFrameの再配置を行います。
image: https://lh6.googleusercontent.com/_9Z4BYR88imo/TQTRm01W30I/AAAAAAAAAhc/eBhL-DDKkSo/s800/RelocatedIcon.png
---
* 概要 [#summary]
`JDesktopPane`のサイズが変更されたとき、アイコン化している`JInternalFrame`の再配置を行います。[https://bugs.openjdk.org/browse/JDK-4765256 [JDK-4765256] REGRESSION: Icons in JDesktopPane not repositioned when pane is resized - Java Bug System]からソースコードの大部分を引用しています。

-&jnlp;
-&jar;
-&zip;
#download(https://lh6.googleusercontent.com/_9Z4BYR88imo/TQTRm01W30I/AAAAAAAAAhc/eBhL-DDKkSo/s800/RelocatedIcon.png)

//#screenshot
#ref(http://lh6.ggpht.com/_9Z4BYR88imo/TQTRm01W30I/AAAAAAAAAhc/eBhL-DDKkSo/s800/RelocatedIcon.png)

**サンプルコード [#v3086042]
* サンプルコード [#sourcecode]
#code(link){{
class ReIconifyDesktopManager extends DefaultDesktopManager {
  public void reIconifyFrame(JInternalFrame jif) {
    deiconifyFrame(jif);
    Rectangle r = getBoundsForIconOf(jif);
    iconifyFrame(jif);
    jif.getDesktopIcon().setBounds(r);
  }
}
}}
#code{{

private void doReIconify(JDesktopPane desktopPane) {
  DesktopManager dm = desktopPane.getDesktopManager();
  if(dm instanceof ReIconifyDesktopManager) {
    ReIconifyDesktopManager rdm = (ReIconifyDesktopManager)dm;
    for(JInternalFrame f: desktopPane.getAllFrames()) {
      if(f.isIcon()) rdm.reIconifyFrame(f);
  if (dm instanceof ReIconifyDesktopManager) {
    ReIconifyDesktopManager rdm = (ReIconifyDesktopManager) dm;
    for (JInternalFrame f: desktopPane.getAllFrames()) {
      if (f.isIcon()) {
        rdm.reIconifyFrame(f);
      }
    }
  }
}
}}

**解説 [#q4580c19]
上記のサンプルでは、JDesktopPaneがリサイズされた場合、以下のような手順で再配置を行っています。
+アイコン化したJInternalFrame を一旦、元のサイズと位置に復元
+アイコン化した場合の位置を再計算
+再びアイコン化
+再計算した位置への移動
* 解説 [#explanation]
- `JDesktopPane`がリサイズされた場合、以下のような手順で再配置を実行
-- `GTKLookAndFeel`を使用する場合、アイコンの移動自体がデフォルトでは不可なのでこの設定は無意味になる

----
GTK L&F の場合、アイコンを移動することは出来ないので、このサンプルには意味がありません。
+ アイコン化した`JInternalFrame`を一旦元のサイズと位置に復元
+ アイコン化した場合の位置を再計算
+ 再びアイコン化
+ 再計算した位置への移動

**参考リンク [#j6e9b199]
- [http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4765256 Bug ID: 4765256 REGRESSION: Icons in JDesktopPane not repositioned when pane is resized]
-- [http://forums.sun.com/thread.jspa?threadID=5122847 Swing - JInternalFrame - iconify in a JDesktopPane]
- [http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4110799 Bug ID: 4110799 JInternalFrame icon position unchanged w/ resize]
* 参考リンク [#reference]
- [https://bugs.openjdk.org/browse/JDK-4765256 [JDK-4765256] REGRESSION: Icons in JDesktopPane not repositioned when pane is resized - Java Bug System]
-- via: [https://community.oracle.com/thread/1374482 Swing - JInternalFrame - iconify in a JDesktopPane]
- [https://bugs.openjdk.org/browse/JDK-4110799 [JDK-4110799] JInternalFrame icon position unchanged w/ resize - Java Bug System]
-- [http://d.hatena.ne.jp/tori31001/20060901 JInternalFrameは最初にアイコン化しておかないと位置が更新されない]
-- [[JInternalFrameを一番手前に表示>Swing/LayeredPane]]

**コメント [#u2043794]
- 1.7.0 b38 で修正されているようです。[http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6647340 Bug ID: 6647340 Minimized JInternalFrame icons appear in incorrect positions if the main frame is resized] -- [[aterai]] &new{2008-12-10 (水) 21:27:26};
- Windows7+WindowsLnFでJDesktopPaneの背景が黒になる: [http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7008416 Bug ID: 7008416 JDesktopPane - Wrong background color with Win7+WindowsLnf] -- [[aterai]] &new{2011-10-04 (火) 16:58:32};
* コメント [#comment]
#comment
- [https://bugs.openjdk.org/browse/JDK-6647340 [JDK-6647340] Minimized JInternalFrame icons appear in incorrect positions if the main frame is resized - Java Bug System]は、`1.7.0 b38`で修正済み。 -- &user(aterai); &new{2008-12-10 (水) 21:27:26};
- `Windows7` + `WindowsLookAndFeel`で`JDesktopPane`の背景が黒になる: [https://bugs.openjdk.org/browse/JDK-7012008 Bug ID: JDK-7012008 JDesktopPane - Wrong background color with Win7+WindowsLnf] -- &user(aterai); &new{2011-10-04 (火) 16:58:32};
// [https://bugs.openjdk.org/browse/JDK-7012008 JDK-7012008 JDesktopPane - Wrong background color with Win7+WindowsLnf - Java Bug System]
// [https://bugs.openjdk.org/browse/JDK-7008416 Bug ID: 7008416 JDesktopPane - Wrong background color with Win7+WindowsLnf] -- &user(aterai); &new{2011-10-04 (火) 16:58:32};

#comment