Swing/CustomDecoratedFrame のバックアップ差分(No.2)
- バックアップ一覧
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/CustomDecoratedFrame へ行く。
- 1 (2010-01-18 (月) 11:27:29)
- 2 (2010-10-04 (月) 18:16:48)
- 3 (2011-05-28 (土) 01:34:14)
- 4 (2011-09-06 (火) 21:27:18)
- 5 (2012-05-10 (木) 15:45:16)
- 6 (2012-08-14 (火) 13:55:29)
- 7 (2012-08-14 (火) 15:56:47)
- 8 (2013-01-02 (水) 14:42:05)
- 9 (2013-08-02 (金) 20:50:48)
- 10 (2013-09-11 (水) 00:36:52)
- 11 (2014-06-30 (月) 03:04:08)
- 12 (2014-11-01 (土) 00:46:09)
- 13 (2014-11-07 (金) 03:10:40)
- 14 (2014-11-08 (土) 01:41:12)
- 15 (2014-11-25 (火) 03:03:31)
- 16 (2014-12-02 (火) 01:47:50)
- 17 (2015-04-01 (水) 20:09:18)
- 18 (2015-04-03 (金) 16:07:28)
- 19 (2016-05-26 (木) 14:38:56)
- 20 (2016-09-29 (木) 17:14:32)
- 21 (2017-03-28 (火) 15:05:45)
- 22 (2017-10-27 (金) 16:26:13)
- 23 (2017-11-02 (木) 15:34:40)
- 24 (2018-01-31 (水) 20:25:08)
- 25 (2018-02-24 (土) 19:51:30)
- 26 (2018-11-24 (土) 17:06:17)
- 27 (2020-11-07 (土) 01:58:08)
- 28 (2022-08-20 (土) 22:15:25)
- 29 (2022-10-22 (土) 22:51:58)
- 追加された行はこの色です。
- 削除された行はこの色です。
TITLE:JFrameのタイトルバーなどを独自のものにカスタマイズする TITLE:JFrameのタイトルバーなどの装飾を独自のものにカスタマイズする #navi(../) RIGHT:Posted by [[terai]] at 2010-01-18 *JFrameのタイトルバーなどを独自のものにカスタマイズする [#f6fbf6c0] JFrameのタイトルバーなどを非表示にして独自に描画し、移動リサイズなどの機能も追加します。 *JFrameのタイトルバーなどの装飾を独自のものにカスタマイズする [#wc20d97b] JFrameのタイトルバーなどを非表示にして独自に描画し、これに移動リサイズなどの機能も追加します。 -&jnlp; -&jar; -&zip; #screenshot **サンプルコード [#da76e44b] #code{{ class ResizeWindowListener extends MouseAdapter { private Rectangle startSide = null; private final JFrame frame; public ResizeWindowListener(JFrame frame) { this.frame = frame; } public void mousePressed(MouseEvent e) { startSide = frame.getBounds(); } public void mouseDragged(MouseEvent e) { if(startSide==null) return; Component c = e.getComponent(); if(c==topleft) { startSide.y += e.getY(); startSide.height -= e.getY(); startSide.x += e.getX(); startSide.width -= e.getX(); }else if(c==top) { startSide.y += e.getY(); startSide.height -= e.getY(); }else if(c==topright) { startSide.y += e.getY(); startSide.height -= e.getY(); startSide.width += e.getX(); }else if(c==left) { startSide.x += e.getX(); startSide.width -= e.getX(); }else if(c==right) { startSide.width += e.getX(); }else if(c==bottomleft) { startSide.height += e.getY(); startSide.x += e.getX(); startSide.width -= e.getX(); }else if(c==bottom) { startSide.height += e.getY(); }else if(c==bottomright) { startSide.height += e.getY(); startSide.width += e.getX(); } frame.setBounds(startSide); } } }} **解説 [#dd2ca04c] 上記のサンプルではタイトルバーを、setUndecorated(true)で非表示にし、移動可能にしたJPanelを追加してタイトルバーにしています。 リサイズは、[[Swing - Undecorated and resizable dialog>http://forums.sun.com/thread.jspa?threadID=5254456]]やBasicInternalFrameUI.javaなどを参考にして、周辺にそれぞれ対応するリサイズカーソルを設定したJLabelを配置しています。 ---- JDK 1.7.0 の場合、JFrameの背景色を透明(frame.setBackground(new Color(0,0,0,0)))にし、ContentPaneの左右上の角をクリアして透明にしています。 **参考リンク [#p98cd47e] -[[Swing - Undecorated and resizable dialog>http://forums.sun.com/thread.jspa?threadID=5254456]] -[[JWindowをマウスで移動>Swing/DragWindow]] -[[JInternalFrameをJFrameとして表示する>Swing/InternalFrameTitleBar]] **コメント [#nc60542a] #comment