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()