Lor*_*tre 8 java linux swing window transparent
我正在尝试创建一个跟随鼠标的圆形窗口,并将点击传递给底层窗口.
我用Python和Qt做这个(参见Python覆盖窗口),然后我切换到Java和Swing.但是我无法使窗口透明.我尝试了这种方法,但它不起作用,但我认为我的系统支持透明度,因为如果我启动Screencast-O-Matic(使用Java),矩形实际上是透明的.
我怎样才能实现这样的目标?(我在Linux KDE4上)
为什么Java教程如何创建半透明和异形Windows无法正常工作?您使用的是最新版本的Java 6还是Java 7?在Java杂志的5月/ 6月刊中,有一个关于需要java 7的形状和透明窗口的教程.您可能需要注册Java杂志才能阅读它.看看你是否可以在你的系统上运行它:
import java.awt.*; //Graphics2D, LinearGradientPaint, Point, Window, Window.Type;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
/**
* From JavaMagazine May/June 2012
* @author josh
*/
public class ShapedAboutWindowDemo {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//switch to the right thread
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame frame = new JFrame("About box");
//turn of window decorations
frame.setUndecorated(true);
//turn off the background
frame.setBackground(new Color(0,0,0,0));
frame.setContentPane(new AboutComponent());
frame.pack();
//size the window
frame.setSize(500, 200);
frame.setVisible(true);
//center on screen
frame.setLocationRelativeTo(null);
}
}
);
}
private static class AboutComponent extends JComponent {
public void paintComponent(Graphics graphics) {
Graphics2D g = (Graphics2D) graphics;
//create a translucent gradient
Color[] colors = new Color[]{
new Color(0,0,0,0)
,new Color(0.3f,0.3f,0.3f,1f)
,new Color(0.3f,0.3f,0.3f,1f)
,new Color(0,0,0,0)};
float[] stops = new float[]{0,0.2f,0.8f,1f};
LinearGradientPaint paint = new LinearGradientPaint(
new Point(0,0), new Point(500,0),
stops,colors);
//fill a rect then paint with text
g.setPaint(paint);
g.fillRect(0, 0, 500, 200);
g.setPaint(Color.WHITE);
g.drawString("My Killer App", 200, 100);
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5646 次 |
| 最近记录: |