日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

Java 7 Swing:创建半透明和成形的Windows

發(fā)布時間:2023/12/3 windows 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java 7 Swing:创建半透明和成形的Windows 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Java 7 Swing支持具有透明和非矩形形狀的窗口。 以下屏幕截圖顯示了創(chuàng)建的不透明度為75%的圓形窗口。

您可以通過在JFrame上使用setOpacity方法更改其不透明度來創(chuàng)建半透明窗口。 請注意,只有底層操作系統(tǒng)支持時,您才能創(chuàng)建半透明窗口。 另外,通過調用setUndecorated(true)確保窗口未裝飾。

改變窗口的形狀,調用setShape內部方法componentResized方法,因此,如果窗口大小,形狀被重新計算為好。

創(chuàng)建半透明圓形窗口的示例代碼如下所示:

import java.awt.Color; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.GridBagLayout; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.awt.geom.Ellipse2D;import javax.swing.JFrame; import javax.swing.JTextArea; import javax.swing.SwingUtilities;public class TranslucentCircularFrame extends JFrame {/*** Creates a frame containing a text area and a button. The frame has a* circular shape and a 75% opacity.*/public TranslucentCircularFrame() {super("Translucent Circular Frame");setLayout(new GridBagLayout());final JTextArea textArea = new JTextArea(3, 50);textArea.setBackground(Color.GREEN);add(textArea);setUndecorated(true);// set the window's shape in the componentResized method, so// that if the window is resized, the shape will be recalculatedaddComponentListener(new ComponentAdapter() {@Overridepublic void componentResized(ComponentEvent e) {setShape(new Ellipse2D.Double(0, 0, getWidth(), getHeight()));}});// make the window translucentsetOpacity(0.75f);setLocationRelativeTo(null);setSize(250, 250);setDefaultCloseOperation(EXIT_ON_CLOSE);setVisible(true);}public static void main(String[] args) {// Create the GUI on the event-dispatching threadSwingUtilities.invokeLater(new Runnable() {@Overridepublic void run() {GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();// check if the OS supports translucencyif (ge.getDefaultScreenDevice().isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency.TRANSLUCENT)) {new TranslucentCircularFrame();}}});} }

參考: Java 7 Swing:由我們的JCG合作伙伴 Fahd Shariff在fahd.blog博客上創(chuàng)建半透明和成形的Windows 。

翻譯自: https://www.javacodegeeks.com/2013/07/java-7-swing-creating-translucent-and-shaped-windows.html

總結

以上是生活随笔為你收集整理的Java 7 Swing:创建半透明和成形的Windows的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。