JInternalFrameをアイコン化した場合のサイズを変更する
Total: 3218, Today: 2, Yesterday: 2
Posted by aterai at
Last-modified:
Summary
JInternalFrameをアイコン化したときに使用されるJDesktopIconのサイズを変更します。
Screenshot

Advertisement
Source Code Examples
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);
}
});
View in GitHub: Java, KotlinDescription
上記のサンプルでは、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 - JDK-7126823 JInternalFrame.getNormalBounds() returns bad value after iconify/deiconify - Java Bug System
- 起動時からの
DefaultDesktopManager#getBoundsForIconOf(...)メソッドをオーバーライドしてサイズ変更desktop.setDesktopManager(new DefaultDesktopManager() { @Override protected Rectangle getBoundsForIconOf(JInternalFrame f) { Rectangle r = super.getBoundsForIconOf(f); r.width = 200; return r; } });DefaultDesktopManager#getBoundsForIconOf(...)メソッドをオーバーライドする方法もあるdesktop.setDesktopManager(new DefaultDesktopManager() { @Override public void iconifyFrame(JInternalFrame f) { Rectangle r = this.getBoundsForIconOf(f); r.width = f.getDesktopIcon().getPreferredSize().width; f.getDesktopIcon().setBounds(r); super.iconifyFrame(f); } });
Reference
- java - Changing DesktopIcon.width on nimbus - Stack Overflow
- JInternalFrame.JDesktopIcon (Java Platform SE 8)
- JInternalFrameのタイトル文字列幅を取得し、その値でJDesktopIconの幅を調整する