| Author |
Error in NapKin Look and Feel
|
Yohan Weerasinghe
Ranch Hand
Joined: Oct 07, 2010
Posts: 481
|
|
Hi,
In the following code, I am triying to apply NapKin Look and Feel to my window. Please have a look at the following code
But, I am keep getting the following exception
keys we didn't overwrite: []
Exception in thread "main" java.awt.IllegalComponentStateException: The frame is decorated
at java.awt.Frame.setBackground(Frame.java:986)
at javax.swing.JFrame.frameInit(JFrame.java:259)
at javax.swing.JFrame.<init>(JFrame.java:181)
at NapKin.<init>(NapKin.java:17)
at NapKin.main(NapKin.java:76)
Java Result: 1
Please help
|
Are you better than me? Then please show me my mistakes..
|
 |
Wendy Gibbons
Bartender
Joined: Oct 21, 2008
Posts: 1098
|
|
when i just looked up how to set a look and feel the java pages gave this example
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
notice it takes a class name, not a class instance.
worth a try
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19214
|
|
setLookAndFeel is overloaded to take either a String with the class name, or an instance of LookAndFeel. The former delegates to the latter.
I've checked the Java 7 source code of java.awt.Frame, especially line 986 (where the exception is thrown from). The relevant code is this:
Apparently, setting a transparent background color for frames is not allowed unless the frame is undecorated, and NapKin uses transparent backgrounds.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Yohan Weerasinghe
Ranch Hand
Joined: Oct 07, 2010
Posts: 481
|
|
Thanks for the reply. I tried the following
UIManager.setLookAndFeel("napkin.NapkinLookAndFeel");
But still no good
|
 |
Yohan Weerasinghe
Ranch Hand
Joined: Oct 07, 2010
Posts: 481
|
|
Rob Spoor wrote:setLookAndFeel is overloaded to take either a String with the class name, or an instance of LookAndFeel. The former delegates to the latter.
I've checked the Java 7 source code of java.awt.Frame, especially line 986 (where the exception is thrown from). The relevant code is this:
Apparently, setting a transparent background color for frames is not allowed unless the frame is undecorated, and NapKin uses transparent backgrounds.
Thanks a lot for your reply. So, does this mean I can't use NapKin Look and Feel in JAVA 7?
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19214
|
|
One thing you can try is the following:
- Don't set the look&feel yet.
- Create your user interface.
- Call setUndecorated(true) on the frame.
- Set the look&feel.
- Call SwingUtilities.updateComponentTreeUI for the frame.
- If necessary, call setUndecorated(false) on the frame.
|
 |
Darryl Burke
Bartender
Joined: May 03, 2008
Posts: 4163
|
|
|
I wonder what would result from calling the static method JFrame.setDefaultLookAndFeelDecorated(true) before setting the LaF and constructing the GUI.
|
luck, db
There are no new questions, but there may be new answers.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19214
|
|
|
Perhaps the same if you'd change that true to false. After all, this method is about being decorated, the other about being undecorated.
|
 |
Yohan Weerasinghe
Ranch Hand
Joined: Oct 07, 2010
Posts: 481
|
|
Rob Spoor wrote:One thing you can try is the following:
- Don't set the look&feel yet.
- Create your user interface.
- Call setUndecorated(true) on the frame.
- Set the look&feel.
- Call SwingUtilities.updateComponentTreeUI for the frame.
- If necessary, call setUndecorated(false) on the frame.
Thanks a lot for the help!! It is awesome!!! It worked!!! I am sooooooooo happy!!! Thanks a lot!
I am posting the code for anyone who has the same issue
|
 |
Yohan Weerasinghe
Ranch Hand
Joined: Oct 07, 2010
Posts: 481
|
|
Thanks for everyone for the help..I really appreciate it
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19214
|
|
You're welcome
|
 |
 |
|
|
subject: Error in NapKin Look and Feel
|
|
|