透明、不可点击和不可聚焦的Java窗口

huangapple 未分类评论43阅读模式
英文:

Transparent,Unclickable and unfocusable window in Java

问题

我想要一个小窗口是不透明的,不会因为任何点击而获得焦点,就像一个幽灵。
我希望当我点击Java窗口时,不会发生任何事情,而下面的窗口会接收鼠标操作!
已经尝试过以下方法:

Frame.java

import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

public class Frame extends JFrame {
    JPanel panel;

    public Frame() {
        this.setBounds(100, 100, 200, 300);
        this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);

        this.setResizable(false);
        this.setAlwaysOnTop(true);
        this.setUndecorated(true);
        this.setAutoRequestFocus(false);

        this.setOpacity((float) 0.5);
        this.setFocusable(false);
        this.setFocusableWindowState(false);
        this.setFocusCycleRoot(false);

        panel = new JPanel();
        getContentPane().add(panel, BorderLayout.CENTER);
        panel.setLayout(null);

        JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
        tabbedPane.setBounds(37, 72, 107, 102);
        panel.add(tabbedPane);

        JLabel label = new JLabel("");
        label.setBounds(10, 10, 120, 20);
        panel.add(label);
    }
}

Main.java

import java.io.IOException;

public class Main {

    public static void main(String[] args) throws IOException, ClassNotFoundException, InstantiationException {
        Frame f = new Frame();
        f.setVisible(true);
    }

}

我的窗口看起来是透明的,但是当我点击它时会响应,我不希望它这样!

英文:

I want a small window to be opaque and cant get focus with any clicks, Like a ghost.
I want that when I click on the java window, nth happens and the bellow window(s) takes the mouse action!
have tried these :

> Frame.java

import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

public class Frame extends JFrame {
	JPanel panel;

	public Frame() {
		this.setBounds(100, 100, 200, 300);
		this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
		
		this.setResizable(false);
		this.setAlwaysOnTop(true);
		this.setUndecorated(true);
		this.setAutoRequestFocus(false);
		
		
		this.setOpacity((float) 0.5);
		this.setFocusable(false);
		this.setFocusableWindowState(false);
		this.setFocusCycleRoot(false);
		
		panel = new JPanel();
		getContentPane().add(panel, BorderLayout.CENTER);
		panel.setLayout(null);

		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane.setBounds(37, 72, 107, 102);
		panel.add(tabbedPane);

		JLabel label = new JLabel("");
		label.setBounds(10, 10, 120, 20);
		panel.add(label);
	}
}

> Main.java

import java.io.IOException;

public class Main {

	public static void main(String[] args) throws IOException, ClassNotFoundException, InstantiationException {
		 Frame f = new Frame();
		 f.setVisible(true);
	}

}

my window appears transparent but it listens to my clicks when I click on it and I don't want it!

huangapple
  • 本文由 发表于 2020年4月9日 22:01:27
  • 转载请务必保留本文链接:https://java.coder-hub.com/61122943.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定