TITLE:DesktopManagerでアイコンの再配置

DesktopManagerでアイコンの再配置

Posted by terai at 2007-01-15
  • 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

概要

JDesktopPaneのサイズが変更されたとき、アイコン化しているJInternalFrameの再配置を行います。[JDK-4765256] REGRESSION: Icons in JDesktopPane not repositioned when pane is resized - Java Bug Systemからソースコードの大部分を引用しています。

概要

JDesktopPaneのサイズが変更されたとき、アイコン化しているJInternalFrameの再配置を行います。Bug ID: 4765256 REGRESSION: Icons in JDesktopPane not repositioned when pane is resizedからソースコードの大部分を引用しています。
  • &jnlp;
  • &jar;
  • &zip;

#screenshot

サンプルコード

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

#spanend
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);
      }
    }
  }
}

解説

上記のサンプルでは、JDesktopPaneがリサイズされた場合、以下のような手順で再配置を行っています。
  1. アイコン化したJInternalFrame を一旦、元のサイズと位置に復元
  2. アイコン化した場合の位置を再計算
  3. 再びアイコン化
  4. 再計算した位置への移動

解説

  • JDesktopPaneがリサイズされた場合、以下のような手順で再配置を実行
    • GTKLookAndFeelを使用する場合、アイコンの移動自体がデフォルトでは不可なのでこの設定は無意味になる

参考リンク

  1. アイコン化したJInternalFrameを一旦元のサイズと位置に復元
  2. アイコン化した場合の位置を再計算
  3. 再びアイコン化
  4. 再計算した位置への移動

参考リンク

コメント

コメント