Swing/WindowShape のバックアップソース(No.1)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- バックアップ を表示
- Swing/WindowShape へ行く。
- 1 (2011-12-19 (月) 19:46:54)
- 2 (2012-03-02 (金) 17:24:36)
- 3 (2012-12-14 (金) 13:43:51)
- 4 (2012-12-26 (水) 05:54:10)
- 5 (2014-12-03 (水) 00:46:42)
- 6 (2015-02-09 (月) 17:17:36)
- 7 (2016-12-02 (金) 17:56:05)
- 8 (2017-11-29 (水) 20:35:57)
- 9 (2019-08-01 (木) 22:55:54)
- 10 (2021-04-01 (木) 04:57:14)
- 11 (2025-01-03 (金) 08:57:02)
- 12 (2025-01-03 (金) 09:01:23)
- 13 (2025-01-03 (金) 09:02:38)
- 14 (2025-01-03 (金) 09:03:21)
- 15 (2025-01-03 (金) 09:04:02)
- 16 (2025-06-19 (木) 12:41:37)
- 17 (2025-06-19 (木) 12:43:47)
TITLE:Windowの形を変更 #navi(../) RIGHT:Posted by [[aterai]] at 2011-12-19 *Windowの形を変更 [#o8807d1b] Windowの形を非矩形図形に変更します。 -&jnlp; -&jar; -&zip; //#screenshot #ref(https://lh4.googleusercontent.com/-f54GogC4jCU/Tu7AbPCJhsI/AAAAAAAABGc/EzG0Tf9ITFI/s800/WindowShape.png) **サンプルコード [#k7ecdb7d] #code{{ JFrame frame = new JFrame(); frame.setUndecorated(true); frame.setAlwaysOnTop(true); frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); frame.getContentPane().add(label); frame.getContentPane().setBackground(Color.GREEN); frame.pack(); String str = textField.getText().trim(); //label.setText(str); TextLayout tl = new TextLayout(str, font, frc); Rectangle2D b = tl.getBounds(); Shape shape = tl.getOutline(AffineTransform.getTranslateInstance(-b.getX(),-b.getY())); frame.setBounds(shape.getBounds()); //frame.setSize(shape.getBounds().width, shape.getBounds().height); com.sun.awt.AWTUtilities.setWindowShape(frame, shape); //frame.setShape(shape); // 1.7.0 frame.setLocationRelativeTo(parent); frame.setVisible(true); }} **解説 [#u7d38289] 上記のサンプルでは、com.sun.awt.AWTUtilities.setWindowShape(...)メソッドを使用して、JFrameの形を変更しています。 - Java 1.7.0 の場合は、Window#setShape(Shape)を使用 //**参考リンク **コメント [#l592ec36] #comment