Swing/WindowOpacity のバックアップソース(No.4)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- バックアップ を表示
- Swing/WindowOpacity へ行く。
- 1 (2010-06-14 (月) 14:13:21)
- 2 (2010-06-14 (月) 22:57:11)
- 3 (2010-06-15 (火) 13:26:11)
- 4 (2011-07-12 (火) 17:35:54)
- 5 (2011-10-18 (火) 19:01:43)
- 6 (2011-10-19 (水) 00:19:54)
- 7 (2012-05-15 (火) 12:49:23)
- 8 (2012-05-15 (火) 14:16:17)
- 9 (2012-09-19 (水) 18:18:48)
- 10 (2012-11-23 (金) 04:44:23)
- 11 (2012-12-30 (日) 09:29:21)
- 12 (2013-09-14 (土) 21:04:15)
- 13 (2013-10-29 (火) 19:26:30)
- 14 (2014-06-10 (火) 18:58:34)
- 15 (2014-11-01 (土) 00:46:09)
- 16 (2014-11-06 (木) 01:40:43)
- 17 (2014-11-13 (木) 19:52:53)
- 18 (2014-12-02 (火) 01:48:11)
- 19 (2015-04-01 (水) 20:11:20)
- 20 (2015-04-10 (金) 13:29:52)
- 21 (2016-06-01 (水) 18:42:41)
- 22 (2017-03-29 (水) 19:44:36)
- 23 (2017-04-04 (火) 14:17:08)
- 24 (2017-11-02 (木) 15:34:40)
- 25 (2018-02-17 (土) 20:19:27)
- 26 (2018-02-24 (土) 19:51:30)
- 27 (2020-02-14 (金) 16:20:33)
- 28 (2021-07-31 (土) 08:07:01)
- 29 (2021-11-17 (水) 04:19:27)
- 30 (2021-12-13 (月) 00:06:37)
- 31 (2022-08-20 (土) 22:15:25)
- 32 (2022-09-26 (月) 11:27:03)
- 33 (2023-02-25 (土) 21:27:51)
TITLE:JFrameを半透明化 #navi(../) RIGHT:Posted by [[aterai]] at 2010-06-14 *JFrameを半透明化 [#ea286453] JFrameを半透明にします。 -&jnlp; -&jar; -&zip; //#screenshot #ref(http://lh5.ggpht.com/_9Z4BYR88imo/TQTWw2d9LNI/AAAAAAAAApw/NXG2EcaSv_s/s800/WindowOpacity.png) **サンプルコード [#l5dd57cc] #code{{ JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame(); //com.sun.awt.AWTUtilities.setWindowOpacity(frame, .5f); com.sun.awt.AWTUtilities.setWindowOpaque(frame, false); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); JPanel p = new JPanel(); p.add(new JButton("JButton")); p.setBackground(new Color(.5f,.8f,.5f,.5f)); frame.getContentPane().add(p); frame.setSize(320, 240); frame.setLocationRelativeTo(null); frame.setVisible(true); }} **解説 [#v5c228ee] com.sun.awt.AWTUtilities.setWindowOpacity(frame, .5f);を使って半透明化すると、フレームのタイトルバーや、子コンポーネントまで半透明化されるので、代わりに上記のサンプルでは以下のようにして半透明化を行っています。 -JFrame.setDefaultLookAndFeelDecorated(true);で、タイトルパーなどをJRootPaneに描画 -com.sun.awt.AWTUtilities.setWindowOpaque(frame, false);でJFrameを完全に透明化 --1.7.0の場合は、代わりに、frame.setBackground(new Color(0,0,0,0)); -ContentPaneにsetBackground(new Color(.5f,.8f,.5f,.5f));で半透明の背景色を設定したパネルを追加 **参考リンク [#pc13cea7] -[http://www.viva-edo.com/komon/edokomon.html 江戸の文様(和風素材・デスクトップ壁紙)] -[http://java.sun.com/developer/technicalArticles/GUI/translucent_shaped_windows/ How to Create Translucent and Shaped Windows] **コメント [#d57b3c09] - そんな簡単にできるんですね!昔画面キャプチャしたり色々苦労した結果断念しました; -- [[riki]] &new{2010-06-14 (月) 22:57:11}; -- AWTUtilities.setWindowOpaqueなどが使えるようになったのは、6u10からですが、上記のサンプルみたいなことができるようになったのは、6u14から(多分[http://bugs.sun.com/view_bug.do?bug_id=6683775 Bug ID: 6683775 Painting artifacts is seen when panel is made setOpaque(false) for a translucent window])みたいですから、最近(ちょうど一年ぐらい)のようです。 -- [[aterai]] &new{2010-06-15 (火) 13:26:11}; #comment