我正在尝试使用Java创建一个覆盖整个屏幕的全屏窗口。此窗口还必须具有一定的透明度(约30%-50%透明)。在说整个屏幕时,我的意思是它涵盖了所有内容(包括OSX / Linux / Windows中的dock / taskbar / menubar),当我说透明时,我的意思是实时透明,而不仅仅是黑客截图。这是我所知道的/尝试过的:
所以我想通过另一个我不知道的黑客来判断这是否可行,那么我很乐意听到。
目标是在桌面上叠加半透明全屏。
答案 0 :(得分:6)
GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException:
The effects for full-screen windows are not supported.
或使用brutte_force
DirectX
冻结我的电脑twicw,只有power_off来保存PC的GPU
import com.sun.awt.AWTUtilities;
import java.awt.Dimension;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class JFrameOpacityExample {
private JFrame myFrame = new JFrame("Test Frame");
private boolean opacity = true;
private boolean resize = true;
private JButton button = new JButton("Opacity");
private JButton button1 = new JButton("Resize");
public JFrameOpacityExample() {
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Object src = evt.getSource();
if (opacity) {
AWTUtilities.setWindowOpacity(myFrame, 0.50f);
opacity = false;
} else {
AWTUtilities.setWindowOpacity(myFrame, 1.0f);
opacity = true;
}
}
});
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Object src = evt.getSource();
if (resize) {
Rectangle dim = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
int h = dim.height;
int w = dim.width;
myFrame.setBounds(00, 00, w, h);
resize = false;
} else {
myFrame.setBounds(100, 100, 400, 400);
resize = true;
}
}
});
JPanel panel = new JPanel();
panel.add(button);
panel.add(button1);
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame.add(panel);
myFrame.setSize(400, 400);
myFrame.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrameOpacityExample jFrameOpacityExample = new JFrameOpacityExample();
}
});
}
}