2010-07-30 35 views
4

我剛剛遇到的實用程序(com.sun.awt.AWTUtilities)使您的JFrame 真的透明。文檔here。這工作非常好。即使在桌面效果打開窗口的Linux環境下(Here a little video)!但是我想在透明的JFrame上製作一個非透明的組件。Java:具有非透明組件的透明Windows?

有誰知道,如果這是可能的,怎麼樣?

這裏是我使用的代碼:

import com.sun.awt.AWTUtilities; 

/* "this" is the JFrame */ 
this.setUndecorated(true); 
AWTUtilities.setWindowOpaque(this, true); 
AWTUtilities.setWindowOpacity(this, 0.5f); 
AWTUtilities.setWindowShape(this, new RoundRectangle2D.Float(0f, 0f, (float) getWidth(), (float) getHeight(), 15f, 15f)); 

感謝

回答

4

IIUC,Translucent Windows適用於整個java.awt.Window和內容,但你可以嘗試如下所示的方法,並在此example

JFrame f = new JFrame(); 
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
f.setBackground(new Color(0f, 0f, 0f, 0.1f)); 
f.setUndecorated(true); 
f.add(new JLabel("<html>Testing<br>1, 2, 3</html>")); 
f.pack(); 
f.setLocationRelativeTo(null); 
f.setVisible(true); 
+0

這不適用於Linux ...在Mac上,這是我的問題的解決方案...悲傷... – 2010-07-31 11:48:53

+1

@Martijn Courteaux:那麼,'AWTUtilities'演示:「請注意,效果可能不支持底層平臺......「 – trashgod 2010-07-31 12:25:56

1

你想要做什麼是對setWindowOpaquefalse繪製低阿爾法背景(或0阿爾法如果你想完全透明)。組件仍然會被繪製成不透明的。請參閱this article並查看每像素半透明