Swing/RelocatedIcon のバックアップの現在との差分(No.5)
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:
概要
JDesktopPane
のサイズが変更されたとき、アイコン化しているJInternalFrame
の再配置を行います。[JDK-4765256] REGRESSION: Icons in JDesktopPane not repositioned when pane is resized - Java Bug Systemからソースコードの大部分を引用しています。
Screenshot
Advertisement
概要
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がリサイズされた場合、以下のような手順で再配置を行っています。- アイコン化したJInternalFrame を一旦、元のサイズと位置に復元
- アイコン化した場合の位置を再計算
- 再びアイコン化
- 再計算した位置への移動
解説
-
JDesktopPane
がリサイズされた場合、以下のような手順で再配置を実行-
GTKLookAndFeel
を使用する場合、アイコンの移動自体がデフォルトでは不可なのでこの設定は無意味になる
-
- - GTK L&F の場合、アイコンを移動することは出来ないので、このサンプルには意味がありません。
- アイコン化した
JInternalFrame
を一旦元のサイズと位置に復元 - アイコン化した場合の位置を再計算
- 再びアイコン化
- 再計算した位置への移動
参考リンク
- Bug ID: 4765256 REGRESSION: Icons in JDesktopPane not repositioned when pane is resized
- Bug ID: 4110799 JInternalFrame icon position unchanged w/ resize
参考リンク
- [JDK-4765256] REGRESSION: Icons in JDesktopPane not repositioned when pane is resized - Java Bug System
- [JDK-4110799] JInternalFrame icon position unchanged w/ resize - Java Bug System