• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error in NapKin Look and Feel

 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. I tried the following

UIManager.setLookAndFeel("napkin.NapkinLookAndFeel");

But still no good
 
Yohan Weerasinghe
Ranch Hand
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5128
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wonder what would result from calling the static method JFrame.setDefaultLookAndFeelDecorated(true) before setting the LaF and constructing the GUI.
 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 507
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for everyone for the help..I really appreciate it
 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic