Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is The Java Tutorials Translucent Window example giving trouble to those playing with jdk7?

Here's the example.

If you build and run TranslucentWindow in let's say, NetBeans IDE 7.0, which supports jdk7, you'll get the following exception:

Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: The frame is decorated
    at java.awt.Frame.setOpacity(Frame.java:960)
    at main.TranslucentWindow.<init>(TranslucentWindow.java:23)
    at main.TranslucentWindow$1.run(TranslucentWindow.java:47)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:705)
    at java.awt.EventQueue.access$000(EventQueue.java:101)
    at java.awt.EventQueue$3.run(EventQueue.java:666)
    at java.awt.EventQueue$3.run(EventQueue.java:664)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:675)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
BUILD SUCCESSFUL (total time: 1 second)

According to this stack trace, the offending line is tw.setOpacity(0.55f). But, as the error indicates, if you invoke setUndecorated(true) on the frame, then it won't throw the exception and will create a translucent window, albeit without any decoration (which is a pain). Is this normal? Shouldn't this code run right "out-of-the-box"? Am I overlooking something?

EDIT

Why does their translucent window appear decorated, or is this custom rendering?

What it is...

enter image description here

What it should be...

enter image description here

like image 448
mre Avatar asked Jun 06 '11 23:06

mre


People also ask

Which method is used to show frame window on screen in Java?

Calling setVisible(true) makes the frame appear onscreen. Sometimes you might see the show method used instead. The two usages are equivalent, but we use setVisible(true) for consistency's sake.

What is window in Java Swing?

JWindow is a part of Java Swing and it can appear on any part of the users desktop. It is different from JFrame in the respect that JWindow does not have a title bar or window management buttons like minimize, maximize, and close, which JFrame has. JWindow can contain several components such as buttons and labels.


1 Answers

I think you need to setUndecorated before setBackground this will fix the problem

like image 75
Benjemaa Avatar answered Oct 10 '22 16:10

Benjemaa