Swing/DesktopIconSize のバックアップ差分(No.4)
- バックアップ一覧
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/DesktopIconSize へ行く。
- 1 (2016-02-15 (月) 00:03:35)
- 2 (2017-04-07 (金) 13:51:51)
- 3 (2017-07-06 (木) 13:54:53)
- 4 (2017-08-03 (木) 13:15:38)
- 5 (2017-08-03 (木) 15:37:21)
- 6 (2017-08-04 (金) 15:50:59)
- 7 (2017-08-21 (月) 21:25:29)
- 8 (2018-08-30 (木) 14:48:42)
- 9 (2019-05-22 (水) 19:35:38)
- 10 (2020-08-25 (火) 15:56:46)
- 11 (2022-02-01 (火) 22:41:03)
- 12 (2022-08-20 (土) 22:15:25)
- 追加された行はこの色です。
- 削除された行はこの色です。
---
category: swing
folder: DesktopIconSize
title: JInternalFrameをアイコン化した場合のサイズを変更する
tags: [JInternalFrame, JDesktopPane, LookAndFeel]
author: aterai
pubdate: 2016-02-15T00:00:57+09:00
description: JInternalFrameをアイコン化したときに使用されるJDesktopIconのサイズを変更します。
image: https://lh3.googleusercontent.com/-TEU2w7fUDtA/VsCIqEiNtoI/AAAAAAAAONk/VP5SO5nYnuw/s800-Ic42/DesktopIconSize.png
---
* 概要 [#summary]
`JInternalFrame`をアイコン化したときに使用される`JDesktopIcon`のサイズを変更します。
#download(https://lh3.googleusercontent.com/-TEU2w7fUDtA/VsCIqEiNtoI/AAAAAAAAONk/VP5SO5nYnuw/s800-Ic42/DesktopIconSize.png)
* サンプルコード [#sourcecode]
#code(link){{
UIManager.put("DesktopIcon.width", 150);
//...
JInternalFrame f = new JInternalFrame(t, true, true, true, true);
f.setDesktopIcon(new JInternalFrame.JDesktopIcon(f) {
@Override public Dimension getPreferredSize() {
return new Dimension(150, 40);
}
});
}}
* 解説 [#explanation]
上記のサンプルでは、`JInternalFrame`をアイコン化したときに使用される`JDesktopIcon`のサイズ変更を`LookAndFeel`毎にテストしています。
- `UIManager.put("DesktopIcon.width", DESKTOPICON_WIDTH);`
-- `MetalLookAndFeel`、`WindowsLookAndFeel`などで、`JDesktopIcon`の幅を指定可能
-- `NimbusLookAndFeel`、`MotifLookAndFeel`では効果がない
- `Override: JInternalFrame.JDesktopIcon#getPreferredSize()`
-- `JInternalFrame.JDesktopIcon#getPreferredSize()`メソッドをオーバーライドして、`LookAndFeel`に依存せずにサイズを変更
-- `MotifLookAndFeel`の場合、タイトルバー状ではなくアイコン状なので、`new Dimension(64, 64 + 32)`を使用
- メモ:
-- デフォルト状態の`NimbusLookAndFeel`で、`JDesktopIcon`の高さが`JInternalFrame`によって変化する?
--- 起動時からの`JInternalFrame`: `height=33`、後でボタンから追加した`JInternalFrame`: `height=27`
--- これは無関係? [https://bugs.openjdk.java.net/browse/JDK-7126823 JDK-7126823 JInternalFrame.getNormalBounds() returns bad value after iconify/deiconify - Java Bug System]
-- `DefaultDesktopManager#getBoundsForIconOf(...)`メソッドをオーバーライドしてサイズ変更することも可能だが、アイコンの位置を計算し直す必要がある
#code{{
desktop.setDesktopManager(new DefaultDesktopManager() {
@Override protected Rectangle getBoundsForIconOf(JInternalFrame f) {
Rectangle r = super.getBoundsForIconOf(f);
r.width = 200;
return r;
}
});
}}
* 参考リンク [#reference]
- [https://stackoverflow.com/questions/35287367/changing-desktopicon-width-on-nimbus java - Changing DesktopIcon.width on nimbus - Stack Overflow]
- [https://docs.oracle.com/javase/jp/8/docs/api/javax/swing/JInternalFrame.JDesktopIcon.html JInternalFrame.JDesktopIcon (Java Platform SE 8)]
* コメント [#comment]
#comment
#comment