简体   繁体   English

使用Netbeans添加自定义外观

[英]Adding custom Look & Feel using Netbeans

I need a bit of help. 我需要一点帮助。 I'm experimenting with Java L&Fs, and I have absolutely no idea how to get Netbeans to actually change the look and feel. 我正在试验Java L&F,但我完全不知道如何让Netbeans真正改变外观。 I'm using the Synthetica Blue Ice L&F, and in the coding where NetBeans has the Nimbus LF coding, I've commented out the Nimbus set and this is what I inserted (extract from original coding): 我正在使用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();
          }
     }

Where NetBeans inserts its own Look and Feel coding, I've commented it out and it looks like this: 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);
               }
          });
     }

Yet, when I run the application, it still looks the same as the default LF. 但是,当我运行该应用程序时,它看起来仍然与默认LF相同。 I've run a script to check and see what LFs I have installed, and this is what I got: 我已经运行了一个脚本来检查并查看我已经安装了哪些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

I've noticed that there's a Look and Feel tab in the design palette. 我注意到设计面板中有一个“外观”选项卡。 Why isn't Synthetica showing there? 为什么Synthetica没有显示在那里?

Seems you need to call UIManager.addAuxiliaryLookAndFeel(LookAndFeel) 1 before trying to use it. 似乎您需要在尝试使用UIManager.addAuxiliaryLookAndFeel(LookAndFeel) 1之前先调用它。

  1. Adds a LookAndFeel to the list of auxiliary look and feels. LookAndFeel添加到辅助外观列表。 The auxiliary look and feels tell the multiplexing look and feel what other LookAndFeel classes for a component instance are to be used in addition to the default LookAndFeel class when creating a multiplexing UI. 辅助外观告诉多路复用外观,当创建多路UI时,除了默认的LookAndFeel类外,还将使用组件实例的其他LookAndFeel类。 The change will only take effect when a new UI class is created or when the default look and feel is changed on a component instance. 仅当创建新的UI类或更改组件实例的默认外观时,此更改才会生效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM