Transparent, click-through, always on top JFrame [closed]

假如想象 提交于 2019-12-05 02:00:26

问题


So I currently have a transparent JFrame that you can click through, but I need it to stay on top of all other windows.

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.

Here is my current code.

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);
}
}

回答1:


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.



来源:https://stackoverflow.com/questions/9372362/transparent-click-through-always-on-top-jframe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!