• category: swing folder: PaletteInternalFrame title: JInternalFrameの縁の装飾を変更してパレット化する tags: [JInternalFrame, JDesktopPane, MetalLookAndFeel] author: aterai pubdate: 2016-03-21T22:17:29+09:00 description: パレット化したJInternalFrameをJDesktopPaneのパレットレイヤーに追加します。 image: https://lh3.googleusercontent.com/-WI8tV2GL8no/Vu_vV8kqSCI/AAAAAAAAOQ4/Os6hBhlLlCYP7L87Qkn_RBlFp8qkUEZrwCCo/s800-Ic42/PaletteInternalFrame.png

概要

パレット化したJInternalFrameJDesktopPaneのパレットレイヤーに追加します。

サンプルコード

JInternalFrame palette = new JInternalFrame("Palette", true, false, true, true);
palette.putClientProperty("JInternalFrame.isPalette", Boolean.TRUE);
palette.setBounds(0, 0, 120, 120);
palette.setMinimumSize(new Dimension(50, 50));
palette.add(new JScrollPane(new JTree()));
palette.setVisible(true);
desktop.add(palette, JDesktopPane.PALETTE_LAYER);
View in GitHub: Java, Kotlin

解説

  • JInternalFrame#putClientProperty("JInternalFrame.isPalette", Boolean.TRUE)で、パレット化
    • MetalLookAndFeelでのみ有効
  • JDesktopPane#add(palette, JDesktopPane.PALETTE_LAYER)でパレットレイヤーに追加
    • パレットレイヤーは、デフォルトレイヤー(JDesktopPane.DEFAULT_LAYER)の一つ上のレイヤーで、常にその下のレイヤーに配置れさたコンポーネントより上に表示される
  • パレット化したJInternalFrameをデフォルトではマウス操作でアイコン化することはできない?
    • JInternalFrame#setIcon(boolean)メソッドを使用すればアイコン化することは可能
    • 最大化はパレットのタイトルバーをダブルクリック、クローズはタイトルバー右端のボタンをクリックで可能

参考リンク

コメント