1

我需要一点帮助。我正在尝试使用 Java L&F,但我完全不知道如何让 Netbeans 真正改变外观。我正在使用 Synthetica Blue Ice L&F,并且在 NetBeans 具有 Nimbus LF 编码的编码中,我已经注释掉了 Nimbus 集,这就是我插入的内容(从原始编码中提取):

import de.javasoft.plaf.synthetica.SyntheticaBlueIceLookAndFeel;
import javax.swing.*;
import java.awt.*;

public MainMenu() {
          initComponents();
          try {
               UIManager.addAuxiliaryLookAndFeel(new SyntheticaBlueIceLookAndFeel());
               UIManager.setLookAndFeel(new SyntheticaBlueIceLookAndFeel());
          } catch (Exception e) {
               e.printStackTrace();
          }
     }

在 NetBeans 插入其自己的外观编码的地方,我已将其注释掉,它看起来像这样:

public static void main(String args[]) {
          /* Set the Nimbus look and feel */
          //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
          /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
           * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
           */

          try {
               UIManager.addAuxiliaryLookAndFeel(new SyntheticaBlueIceLookAndFeel());
               UIManager.setLookAndFeel(new SyntheticaBlueIceLookAndFeel());
          } catch (Exception e) {
               e.printStackTrace();
          }

//          try {
//               for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
//                    JOptionPane.showMessageDialog(null, info.getClassName());
//                    if ("Nimbus".equals(info.getName())) {
//                         javax.swing.UIManager.setLookAndFeel(info.getClassName());
//                         break;
//                    }
//               }
//          } catch (ClassNotFoundException ex) {
//               java.util.logging.Logger.getLogger(MainMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//          } catch (InstantiationException ex) {
//               java.util.logging.Logger.getLogger(MainMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//          } catch (IllegalAccessException ex) {
//               java.util.logging.Logger.getLogger(MainMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//          } catch (javax.swing.UnsupportedLookAndFeelException ex) {
//               java.util.logging.Logger.getLogger(MainMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//          }
//          }
//          catch (Exception e){
//               java.util.logging.Logger.getLogger(MainMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, e);
//          }

          //</editor-fold>

          /* Create and display the form */
          java.awt.EventQueue.invokeLater(new Runnable() {
               public void run() {
                    new MainMenu().setVisible(true);
               }
          });
     }

然而,当我运行应用程序时,它看起来仍然与默认的 LF 相同。我已经运行了一个脚本来检查并查看我安装了哪些 LF,这就是我得到的:

javax.swing.plaf.metal.MetalLookAndFeel
javax.swing.plaf.nimbus.NimbusLookAndFeel
com.sun.java.swing.plaf.motif.MotifLookAndFeel
com.sun.java.swing.plaf.windows.WindowsLookAndFeel
com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel

我注意到设计调色板中有一个外观选项卡。为什么 Synthetica 没有显示在那里?

4

1 回答 1

1

似乎您需要在尝试使用它之前调用1 。UIManager.addAuxiliaryLookAndFeel(LookAndFeel)

  1. LookAndFeel在辅助外观列表中添加一个。辅助外观告诉多路复用外观,在创建多路复用 UI 时LookAndFeel,除了默认类之外,还要使用组件实例的哪些其他类。LookAndFeel仅当创建新的 UI 类或更改组件实例的默认外观时,更改才会生效。

于 2013-10-19T15:43:02.367 回答