Today with swing to do a simulation QQ2009 login interface, using the open source Look&feel (substance), in the process of using some problems encountered, but also learned some skills.
Substance (https://substance.dev.java.net) has a lot of appearances to choose from, and it's pretty and provides a powerful API for developers to use. Substance is now
developed to the 5.2RC version, I started with the 5.1 version, but in the process of using some bugs found, when I use the watermark provided in substance, there are a lot of exceptions, this bug was not in 5.0, and then I downloaded the latest 5.2RC version, this issue in the 5.2 version has been resolved. If you want, you can click here to download .
The first question: How to use Look&feel fully?
You may ask, what is the full use of Look&feel? Here is not urgent to explain, first let everyone see a pair;
Let's see if the picture above has been used Look&feel? The answer is correct, but not complete, because his title bar has not changed, the full use of Look&feel after the following:
Does it feel very different? This is a piece of cake for swing veteran, but it's harder for beginners because they see that many of the tutorials that use Look&feel are like
Such a:
Uimanager.setlookandfeel (NewSubstanceofficeblue2007lookandfeel ());
or this:
Try{
Uimanager.setlookandfeel ("Org.jvnet.substance.skin.SubstanceRavenGraphiteLookAndFeel");
}Catch(Exception e) {
System.out.println ("Substance Raven Graphite failed to initialize");
}
Or maybe I'm too much of a cook. Anyway I'm not sure how to make the title bar change until I'm really learning about the look and use of swing.
To change the title bar in fact, as long as one sentence is enough, that is, in the main method to add such a sentence:
Jframe.setdefaultlookandfeeldecorated (true);
If you want JDialog to change, add: jdilog.setdefaultlookandfeeldecorated (TRUE);
The following is the final finished interface, using the Substance in Officeblue2007lookandfeel :
Second question, how to add a watermark to an application or a background?
The official documentation says little, there is no specific use of examples, and later downloaded the source of substance to see how to use.
Here is my reference to the official source code written in the main method of a section of the core
Jframe.setdefaultlookandfeeldecorated (TRUE);
Jdialog.setdefaultlookandfeeldecorated (TRUE);
Try{
Substanceimagewatermark watermark =NewSubstanceimagewatermark (Loginframe.class. getResourceAsStream ("/demo/001.jpg"));
Watermark.setkind (Imagewatermarkkind.screen_center_scale);
Substanceskin skin =NewOfficeblue2007skin (). Withwatermark (watermark); Initialize the skin with a watermark
Uimanager.setlookandfeel (NewSubstanceofficeblue2007lookandfeel ());
Substancelookandfeel.setskin (skin); Set Skin
}Catch(Unsupportedlookandfeelexception ex) {
Logger.getlogger (Loginframe.class. GetName ()). log (Level.severe,NULL, ex);
}
The position of the code in the above code is immutable, and that is Substancelookandfeel.setskin (skin); .
it has to be in Uimanager.setlookandfeel (new Substanceofficeblue2007lookandfeel ()); The bottom of this sentence.
Otherwise you won't see the effect of the watermark. is a watermark and no watermark of the contrast chart (the left is a watermark, the right is no watermark):
One more official: What do you see in Swing's Office2007 interface?
Ext.: http://www.blogjava.net/gml520/archive/2009/05/23/277603.html