Question

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. 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):

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:

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. I've run a script to check and see what LFs I have installed, and this is what I got:

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?

Était-ce utile?

La solution

Seems you need to call UIManager.addAuxiliaryLookAndFeel(LookAndFeel)1 before trying to use it.

  1. Adds a LookAndFeel to the list of auxiliary look and feels. 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. 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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top