Just Move the below line before calling frame.setOpacity(0.75f);
frame.setUndecorated(true);
Question
I'm trying to make translucent window, I've read many posts that say that it doesn't work in Java 7 at all, some solved this problem, but their ways don't work for me. If I try to make panel translucent, background just bacomes darker. Here's my class:
public class MainCycle {
public static DrawPanel drawPanel = new DrawPanel();
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable(){
public void run(){
JFrame frame = new JFrame();
JFrame.setDefaultLookAndFeelDecorated(true);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
System.out.println(gd.isWindowTranslucencySupported(WindowTranslucency.TRANSLUCENT));
frame.setOpacity(0.75f);
frame.setUndecorated(true);
frame.setBounds(0, 0, (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth(), (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight());
frame.setContentPane(drawPanel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
}
Output:
true
Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: The frame is decorated
at java.awt.Frame.setOpacity(Unknown Source)
at com.bg.my_paint_program.MainCycle$1.run(MainCycle.java:31)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Can you help me someway?
Solution
Just Move the below line before calling frame.setOpacity(0.75f);
frame.setUndecorated(true);