透明,点击,始终在顶部JFrame [英] Transparent, click-through, always on top JFrame
问题描述
所以我目前有一个透明的JFrame,你可以点击,但我需要它保持在所有其他窗口之上。
So I currently have a transparent JFrame that you can click through, but I need it to stay on top of all other windows.
假设你有一个浏览器打开,我希望JFrame能够保持最佳状态,但能够捕捉击键和鼠标点击。
Let's say you have a browser open, I want the JFrame to stay on top of it but be able to catch the keystrokes and mouse clicks.
这是我当前的代码。
public class TransparentWindow extends JFrame {
private static URL URI;
public TransparentWindow() {
initComponents();
}
@SuppressWarnings("unchecked")
private void initComponents() {
setExtendedState(Frame.MAXIMIZED_BOTH);
setIconImage(Toolkit.getDefaultToolkit().getImage(URI));
setResizable(false);
setUndecorated(true);
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
setAlwaysOnTop(true);
System.setProperty("sun.java2d.noddraw", "true");
WindowUtils.setWindowTransparent(this, true);
WindowUtils.setWindowAlpha(this, 0.6f);
addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
}
@Override
public void keyTyped(KeyEvent e) {
}
});
}
public static void main(String[] args) {
try {
URI = new URL("http://i.imgur.com/xtZK0.png");
} catch (MalformedURLException e) {
e.printStackTrace();
}
new TransparentWindow().setVisible(true);
}
}
推荐答案
你可能需要做一个超过jframe的java进程,
jframe在没有聚焦的时候无法捕捉到键击,你做这类事情的唯一方法就是把焦点放在你的jframe上每当你丢失它,意味着不可能使用任何其他窗户打开。
您可能需要更改语言。
you probably need to do a java process more than a jframe,
jframe can't catch key stroke when not focus, the only way for you to do such a things is to give the focus to you're jframe every time you lost it, meaniing no possible use of any other windows open.
You probably need to change langage.
这篇关于透明,点击,始终在顶部JFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!