Swing/RelocatedIcon のバックアップの現在との差分(No.14)
- category: swing folder: RelocatedIcon title: DesktopManagerでアイコンの再配置 tags: [DesktopManager, JDesktopPane, JInternalFrame] author: aterai pubdate: 2007-01-15 pubdate: 2007-01-15T12:27:58+09:00 description: JDesktopPaneのサイズが変更されたとき、アイコン化しているJInternalFrameの再配置を行います。 image:
概要
JDesktopPane
のサイズが変更されたとき、アイコン化しているJInternalFrame
の再配置を行います。Bug ID: 4765256 REGRESSION: Icons in JDesktopPane not repositioned when pane is resizedからソースコードの大部分を引用しています。
JDesktopPane
のサイズが変更されたとき、アイコン化しているJInternalFrame
の再配置を行います。[JDK-4765256] REGRESSION: Icons in JDesktopPane not repositioned when pane is resized - Java Bug Systemからソースコードの大部分を引用しています。
Screenshot
Advertisement
サンプルコード
class ReIconifyDesktopManager extends DefaultDesktopManager {
public void reIconifyFrame(JInternalFrame jif) {
deiconifyFrame(jif);
Rectangle r = getBoundsForIconOf(jif);
iconifyFrame(jif);
jif.getDesktopIcon().setBounds(r);
}
}
#spandel
View in GitHub: Java, Kotlin#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);
}
}
}
}
解説
上記のサンプルでは、JDesktopPane
がリサイズされた場合、以下のような手順で再配置を行っています。
-
JDesktopPane
がリサイズされた場合、以下のような手順で再配置を実行-
GTKLookAndFeel
を使用する場合、アイコンの移動自体がデフォルトでは不可なのでこの設定は無意味になる
-
- アイコン化した
JInternalFrame
を一旦、元のサイズと位置に復元 - アイコン化した
JInternalFrame
を一旦元のサイズと位置に復元 - アイコン化した場合の位置を再計算
- 再びアイコン化
- 再計算した位置への移動
- -
GTKLookAndFeel
の場合、アイコンを移動することは出来ないので、このサンプルには意味がありません。
参考リンク
- Bug ID: 4765256 REGRESSION: Icons in JDesktopPane not repositioned when pane is resized
- [JDK-4765256] REGRESSION: Icons in JDesktopPane not repositioned when pane is resized - Java Bug System
- Bug ID: 4110799 JInternalFrame icon position unchanged w/ resize
- [JDK-4110799] JInternalFrame icon position unchanged w/ resize - Java Bug System