Swing/WindowDecorationStyle のバックアップ(No.2)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- Swing/WindowDecorationStyle へ行く。
- 1 (2013-06-17 (月) 02:37:17)
- 2 (2014-12-26 (金) 15:52:19)
- 3 (2015-04-01 (水) 20:10:51)
- 4 (2015-04-10 (金) 13:30:05)
- 5 (2017-03-03 (金) 12:00:15)
- 6 (2018-01-06 (土) 18:59:26)
- 7 (2019-10-10 (木) 17:39:36)
- 8 (2021-05-13 (木) 18:18:20)
- 9 (2024-02-16 (金) 08:27:03)
- 10 (2025-01-03 (金) 08:57:02)
- 11 (2025-01-03 (金) 09:01:23)
- 12 (2025-01-03 (金) 09:02:38)
- 13 (2025-01-03 (金) 09:03:21)
- 14 (2025-01-03 (金) 09:04:02)
- title: JRootPaneにリサイズのための装飾を設定する tags: [JFrame, JRootPane, JLayeredPane, JInternalFrame, MetalLookAndFeel] author: aterai pubdate: 2013-06-17T02:37:17+09:00 description: JFrame自体の装飾を削除し、JRootPaneにリサイズのためのウィンドウ装飾(透明)を設定します。
概要
JFrame
自体の装飾を削除し、JRootPane
にリサイズのためのウィンドウ装飾(透明)を設定します。
Screenshot

Advertisement
サンプルコード
JFrame frame = new JFrame();
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception e) {
e.printStackTrace();
}
//XXX: JFrame frame = new JFrame();
frame.setUndecorated(true);
JRootPane root = frame.getRootPane();
root.setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
JLayeredPane layeredPane = root.getLayeredPane();
Component c = layeredPane.getComponent(1);
if(c instanceof JComponent) {
JComponent orgTitlePane = (JComponent)c;
orgTitlePane.setVisible(false);
//layeredPane.remove(orgTitlePane);
}
//JComponent dummyTitlePane = new JLabel();
//layeredPane.add(dummyTitlePane, JLayeredPane.FRAME_CONTENT_LAYER);
//dummyTitlePane.setVisible(true);
JPanel p = new JPanel(new BorderLayout());
p.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
p.setBackground(new Color(1f,1f,1f,.01f));
p.add(internalFrame);
frame.getContentPane().add(p);
View in GitHub: Java, Kotlin解説
JFrame
の装飾を削除JFrame#setUndecorated(true);
JInternalFrame
をContentPane
に追加- JInternalFrameをJFrameとして表示する
JFrame
の背景色をJFrame#setBackground(new Color(0,0,0,0));
で透明化
JRootPane
に装飾を追加、変更JRootPane#setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
で装飾を追加し、リサイズのためのMouseMotionListener
などを利用- JFrameのタイトルバーなどの装飾を独自のものにカスタマイズするは、このリサイズのための
MouseMotionListener
も独自に追加している
- JFrameのタイトルバーなどの装飾を独自のものにカスタマイズするは、このリサイズのための
JLayeredPane
からタイトルバーを削除- 上辺でリサイズできない
- マウスでリサイズ可能な領域を作成するために、
ContentPane
にほぼ透明なBorder
をもつJPanel
を追加
MetalLookAndFeel
のみLookAndFeel#getSupportsWindowDecorations()
がtrue
LookAndFeel
を変更する場合は、ContentPane
以下から更新することで、JRootPane#setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
が無効にならないようにする必要がある
for(Window window: Frame.getWindows()) {
if(window instanceof RootPaneContainer) {
RootPaneContainer rpc = (RootPaneContainer)window;
SwingUtilities.updateComponentTreeUI(rpc.getContentPane());
}
}