Swing-nimbus look and feel Setting

Source: Internet
Author: User

Swing-nimbus look and feel SettingI, Java 6 and Java 7 set the Nimbus style

In Java 6, swing has a new interface style-nimbus, with the class name Com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel.

After the Java 7 update, Nimbus-style implementation class moved to Javax.swing.plaf.nimbus.NimbusLookAndFeel, while for backwards compatibility, com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel purely direct inheritance Since Javax.swing.plaf.nimbus.NimbusLookAndFeel.

Under normal circumstances, we can use the following way to set the Nimbus style (the official wording, this writing in Java 5 without Nimbus support will not set Nimbus, not cause error):

Try {    for  (Lookandfeelinfo info:UIManager.getInstalledLookAndFeels ()) {        if ("Nimbus". Equals (Info.getname ())) {            Uimanager.setlookandfeel (Info.getclassname ());              Break ;        }     Catch (Exception e) {    //  If Nimbus is not available, you can set the GUI to another look and FE El.}
Second, Nimbus modify the default settings of the bug and improve the scheme

This setting does not have any problems, but when we need to modify some of the default settings of Nimbus, such as setting the overall style background color to white, we will first think of using Uimanger.put ("background", Color.White), Unfortunately, Nimbus's support for this general setup is flawed--not responding. After searching around the solution, we found that some of the settings of Nimbus can be successfully set up in the following ways (this is an error in Java 5, the class cannot be found):

Uimanager.setlookandfeel (new  Nimbuslookandfeel () {    @Override    public  Uidefaults GetDefaults () {        super. GetDefaults ();        Defaults.put ("Background", color.white);        Defaults.put ("Scrollbar.width", ten);         return defaults;    }});

Put code snippet 2 in a method of a new class and put the line Uimanager.setlookandfeel (Info.getclassname ()) in code fragment 1, and replace it with this new method, which is compiled in Java 6 and can be run in Java 5. Do not set Nimbus style nor error.

Iii. settings in desktop and applet mode

Put the above settings Nimbus style code in one method, Swingtool.setnimbuslookandfeel ().

In desktop mode, in the first sentence of the main () method, add:

Swingtool.setnimbuslookandfeel ()

and in The start method of the Applet init () has the following code at the last location:

Swingtool.setnimbuslookandfeel (); Swingutilities.updatecomponenttreeui (this);

Note that in applet mode, it is important to put the above code at the end of the Init () method, which is not valid at the beginning of the method

Copy to Google TranslateTranslation ResultsSwingtool.setnimbuslookandfeel()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.