Full screen java window with transparency

I am trying to create a full screen window that spans the entire screen using Java. This window should also have transparency (about 30% -50% transparency). Speaking full screen, I mean that it covers everything (including the dock / taskbar / menu in OSX / Linux / Windows), and when I speak with transparency, I mean transparency in real time, not just a hacked screen shot. Here is what I know / tried:

  • Using the Java Fullscreen API: while it creates a full full-screen mode, you cannot have transparency (only an opaque color). One hack is to take a screenshot of the entire desktop and set it as the background for the window, but this means that this is not real-time transparency.
  • Setting the window size according to the screen size: while it fills the whole screen, on some operating systems (for example, Mac OS X) the window will be displayed behind the dock / menu, and not above it. However, transparency works here.
  • Using setWindowOpacity API: it works in the second case, but not in the first (Fullscreen API)
  • Using setBackground with alpha: it works like setWindowOpacity, but only on certain operating systems. But also does not work with Fullscreen API.
  • Use JFrame / JWindow / JDialog / Frame / Window: tried every window model, I could, with no luck

So, I ask if this is possible with another hack that I don’t know about, then I would be happy to hear about it.

The goal is to impose a translucent full-screen mode on the desktop.

+8
java swing transparency fullscreen jframe
source share
1 answer
  • only possible with visible TaskBar ei

.

GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds(); 
  • otherwise you got an exception

.

 Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: The effects for full-screen windows are not supported. 

or using brutte_force to DirectX froze my twicw file, only power_off to save the 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(); } }); } } 
+6
source share

All Articles