Swing/WindowShape のバックアップソース(No.2)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- バックアップ を表示
- Swing/WindowShape へ行く。
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)を使用 **参考リンク [#c00b334c] -[http://blogs.oracle.com/thejavatutorials/entry/translucent_and_shaped_windows_in Translucent and Shaped Windows in JDK7 (The Java Tutorials' Weblog)] **コメント [#l592ec36] #comment