Nimbus 外观和感觉

原文: https://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/nimbus.html

Nimbus 是 Java SE 6 Update 10(6u10)版本中引入的优质跨平台外观。来自 SwingSet3 的以下屏幕截图显示了 Nimbus 的外观和感觉。

SwingSet3 Screen capture Using Nimbus Look and Feel

Nimbus 使用 Java 2D 矢量图形来绘制用户界面(UI),而不是静态位图,因此可以在任何分辨率下清晰地呈现 UI。

Nimbus 是高度可定制的。您可以按原样使用 Nimbus 外观,或者您可以皮肤(自定义)使用您自己的品牌外观。

为了向后兼容,Metal 仍然是默认的 Swing 外观,但您可以通过以下三种方式之一更改为 Nimbus:

  • Add the following code to the event-dispatching thread before creating the graphical user interface (GUI):

    1. import javax.swing.UIManager.*;
    2. try {
    3. for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
    4. if ("Nimbus".equals(info.getName())) {
    5. UIManager.setLookAndFeel(info.getClassName());
    6. break;
    7. }
    8. }
    9. } catch (Exception e) {
    10. // If Nimbus is not available, you can set the GUI to another look and feel.
    11. }

    第一行代码检索平台的所有已安装外观实现的列表,然后遍历列表以确定 Nimbus 是否可用。如果是这样,Nimbus 就像外观一样。


    Version Note: Do not set the Nimbus look and feel explicitly by invoking the UIManager.setLookAndFeel method because not all versions or implementations of Java SE 6 support Nimbus. Additionally, the location of the Nimbus package changed between the JDK 6 Update 10 and JDK 7 releases. Iterating through all installed look and feel implementations is a more robust approach because if Nimbus is not available, the default look and feel is used. For the JDK 6 Update 10 release, the Nimbus package is located at com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel.


  • 在命令行中将 Nimbus 指定为特定应用程序的默认外观,如下所示:

    1. java -Dswing.defaultlaf = javax.swing.plaf.nimbus.NimbusLookAndFeel MyApp
  • 通过在< HTG0]中添加以下行,永久性地为 Nimbus 设置默认外观。 _JAVA_HOME_ &gt; /lib/swing.properties文件:

    1. swing.defaultlaf=javax.swing.plaf.nimbus.NimbusLookAndFeel

    如果swing.properties文件尚不存在,则需要创建它。