File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Error in NapKin Look and Feel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Error in NapKin Look and Feel" Watch "Error in NapKin Look and Feel" New topic
Author

Error in NapKin Look and Feel

Yohan Weerasinghe
Ranch Hand

Joined: Oct 07, 2010
Posts: 499

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: 1107

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: 19718
    
  20

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 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Yohan Weerasinghe
Ranch Hand

Joined: Oct 07, 2010
Posts: 499

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: 499

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: 19718
    
  20

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: 4638
    
    5

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: 19718
    
  20

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: 499

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: 499

Thanks for everyone for the help..I really appreciate it
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error in NapKin Look and Feel