添加自定义Look&感觉使用Netbeans

时间:2013-10-19 15:30:33

标签: java swing netbeans look-and-feel synthetica

我需要一些帮助。我正在尝试Java L& Fs,我完全不知道如何让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没有在那里展示?

1 个答案:

答案 0 :(得分:1)

在尝试使用之前,您似乎需要致电UIManager.addAuxiliaryLookAndFeel(LookAndFeel) 1

  1.   

    LookAndFeel添加到辅助外观列表中。辅助外观告诉多路复用外观在创建多路复用UI时,除了默认LookAndFeel类之外,还要使用组件实例的其他LookAndFeel类。只有在创建新UI类或在组件实例上更改默认外观时,更改才会生效。

  2.