2015-12-30 60 views
-2

我爲我的Java Swings代碼使用Seaglass外觀。但我不斷收到這個錯誤。java.lang.NoClassDefFoundError:sun/swing/plaf/synth/SynthUI

Exception in thread "main" java.lang.NoClassDefFoundError: sun/swing/plaf/synth/SynthUI 
    at java.lang.ClassLoader.defineClass1(Native Method) 
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800) 
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) 
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449) 
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71) 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361) 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358) 
    at java.lang.Class.forName0(Native Method) 
    at java.lang.Class.forName(Class.java:278) 
    at javax.swing.SwingUtilities.loadSystemClass(SwingUtilities.java:1873) 
    at javax.swing.UIDefaults.getUIClass(UIDefaults.java:686) 
    at javax.swing.UIDefaults.getUI(UIDefaults.java:758) 
    at javax.swing.UIManager.getUI(UIManager.java:1013) 
    at javax.swing.JRootPane.updateUI(JRootPane.java:483) 
    at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1230) 
    at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1245) 
    at javax.swing.SwingUtilities.updateComponentTreeUI(SwingUtilities.java:1221) 
    at jsupport.lookandfeel.LookAndFeel.changeLookandFeel(LookAndFeel.java:246) 
    at jsupport.lookandfeel.LookAndFeel.<init>(LookAndFeel.java:22) 
    at jsupport.lookandfeel.Main.main(Main.java:11) 
Caused by: java.lang.ClassNotFoundException: sun.swing.plaf.synth.SynthUI 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366) 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358) 
    ... 25 more 

我做了一些研究,發現SEAGLASS不使用Java 7(我目前的版本),因此該問題的工作。但是我正在尋找一種能夠使其工作的方式,或者如果任何人有任何可以與Java 7版本完美配合的演示版本,這將非常有幫助。

我的代碼:

private void changeLookandFeel() { 
    try { 

     UIManager.removeAuxiliaryLookAndFeel(UIManager.getLookAndFeel()); 
     SyntheticaLookAndFeel.setWindowsDecorated(false); 
     UIManager.setLookAndFeel(UIMANAGER_STRING); 
     UIManager.setLookAndFeel("de.javasoft.plaf.synthetica.SyntheticaBlueIceLookAndFeel"); 

     for (int i = 0; i < LookAndFeel.getFrames().length; ++i) { 
      SwingUtilities.updateComponentTreeUI(LookAndFeel.getFrames()[i]); 
      SwingUtilities.updateComponentTreeUI(this); 
     } 
     SwingUtilities.updateComponentTreeUI(this); 

    } catch (Exception ex) { 
     try { 
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
      UIManager.setLookAndFeel("de.javasoft.plaf.synthetica.SyntheticaBlackEyeLookAndFeel"); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 

的罐子,我使用 enter image description here

+1

顯然,你錯過了在運行時的罐子。 –

+0

我已添加所有的罐子:seaglass,synthetica,junit – Anuja

+0

可能會添加多次? –

回答

0

最好的方法來測試兼容性檢查代碼是否正在與Java 6中(如果你使用任何像Intellij的eclipse這樣的IDE,他們可以選擇使用較低的Java版本編譯文件)。

從錯誤看來,它在運行時似乎無法找到類或它所在的路徑。您可以嘗試java -cp指定路徑。

+0

但是我不打算使用JDK 6。我正在使用netbeans。 – Anuja

+0

@Anuja使用Java 6驗證它是否是您的配置問題或Java 7的問題,Netbeans可以使用多個JDK編譯/執行您的項目(我已經使用JDK 3至8進行了設置) – MadProgrammer

+0

是的,它可以與JDK 6但我不想使用JDK6,因爲我的應用程序需要JDK 7來運行其組件的一部分。 – Anuja

-1

@Anuja U請按照此鏈接

Link

package jsupport.lookandfeel; 

import de.javasoft.plaf.synthetica.SyntheticaLookAndFeel; 
import java.awt.Color; 
import javax.swing.SwingUtilities; 
import javax.swing.UIManager; 


public class LookAndFeel extends javax.swing.JFrame { 

    public static Color FormColor = new Color(140,205,250); 
    public static Color lblFontColor = new Color(0,0,0); 
    public static String UIMANAGER_STRING = "de.javasoft.plaf.synthetica.SyntheticaSkyMetallicLookAndFeel"; 

    public LookAndFeel() { 

     changeLookandFeel(); 
     initComponents(); 
    } 


    @SuppressWarnings("unchecked") 
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents 
    private void initComponents() { 

     pnl_main = new javax.swing.JPanel(); 
     jButton1 = new javax.swing.JButton(); 
     jComboBox1 = new javax.swing.JComboBox(); 
     jCheckBox1 = new javax.swing.JCheckBox(); 
     jTextField1 = new javax.swing.JTextField(); 
     jScrollPane1 = new javax.swing.JScrollPane(); 
     jTextArea1 = new javax.swing.JTextArea(); 
     jLabel1 = new javax.swing.JLabel(); 
     jRadioButton1 = new javax.swing.JRadioButton(); 
     jButton2 = new javax.swing.JButton(); 
     jMenuBar1 = new javax.swing.JMenuBar(); 
     jMenu1 = new javax.swing.JMenu(); 
     jMenu2 = new javax.swing.JMenu(); 
     jMenuItem1 = new javax.swing.JMenuItem(); 
     jMenuItem2 = new javax.swing.JMenuItem(); 
     jMenuItem3 = new javax.swing.JMenuItem(); 
     jMenuItem4 = new javax.swing.JMenuItem(); 
     jMenuItem5 = new javax.swing.JMenuItem(); 

     setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 
     setUndecorated(true); 

     pnl_main.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); 

     jButton1.setText("Button"); 
     pnl_main.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 70, 70, 30)); 

     jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); 
     pnl_main.add(jComboBox1, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 80, 110, -1)); 

     jCheckBox1.setText("jCheckBox1"); 
     pnl_main.add(jCheckBox1, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 80, 90, -1)); 

     jTextField1.setText("jTextField1"); 
     pnl_main.add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 140, 140, -1)); 

     jTextArea1.setColumns(20); 
     jTextArea1.setRows(5); 
     jScrollPane1.setViewportView(jTextArea1); 

     pnl_main.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 140, 180, 60)); 

     jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); 
     jLabel1.setText("Look And Feel"); 
     pnl_main.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 20, 130, 20)); 

     jRadioButton1.setText("jRadioButton1"); 
     pnl_main.add(jRadioButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 40, -1, -1)); 

     jButton2.setText("Exit"); 
     jButton2.addActionListener(new java.awt.event.ActionListener() { 
      public void actionPerformed(java.awt.event.ActionEvent evt) { 
       jButton2ActionPerformed(evt); 
      } 
     }); 
     pnl_main.add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 220, 90, 30)); 

     jMenuBar1.setMinimumSize(new java.awt.Dimension(60, 30)); 
     jMenuBar1.setPreferredSize(new java.awt.Dimension(60, 30)); 

     jMenu1.setText("File"); 
     jMenuBar1.add(jMenu1); 

     jMenu2.setText("Look And Feel"); 

     jMenuItem1.setFont(new java.awt.Font("Tahoma", 0, 12)); 
     jMenuItem1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Issue.png"))); // NOI18N 
     jMenuItem1.setText("Skye Metal"); 
     jMenuItem1.addActionListener(new java.awt.event.ActionListener() { 
      public void actionPerformed(java.awt.event.ActionEvent evt) { 
       jMenuItem1ActionPerformed(evt); 
      } 
     }); 
     jMenu2.add(jMenuItem1); 

     jMenuItem2.setFont(new java.awt.Font("Tahoma", 0, 12)); 
     jMenuItem2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/ItemMaster.png"))); // NOI18N 
     jMenuItem2.setText("Blue Moon"); 
     jMenuItem2.addActionListener(new java.awt.event.ActionListener() { 
      public void actionPerformed(java.awt.event.ActionEvent evt) { 
       jMenuItem2ActionPerformed(evt); 
      } 
     }); 
     jMenu2.add(jMenuItem2); 

     jMenuItem3.setFont(new java.awt.Font("Tahoma", 0, 12)); 
     jMenuItem3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/ItemType.png"))); // NOI18N 
     jMenuItem3.setText("Classy"); 
     jMenuItem3.addActionListener(new java.awt.event.ActionListener() { 
      public void actionPerformed(java.awt.event.ActionEvent evt) { 
       jMenuItem3ActionPerformed(evt); 
      } 
     }); 
     jMenu2.add(jMenuItem3); 

     jMenuItem4.setFont(new java.awt.Font("Tahoma", 0, 12)); 
     jMenuItem4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/look.png"))); // NOI18N 
     jMenuItem4.setText("White Vision"); 
     jMenuItem4.addActionListener(new java.awt.event.ActionListener() { 
      public void actionPerformed(java.awt.event.ActionEvent evt) { 
       jMenuItem4ActionPerformed(evt); 
      } 
     }); 
     jMenu2.add(jMenuItem4); 

     jMenuItem5.setFont(new java.awt.Font("Tahoma", 0, 12)); 
     jMenuItem5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/inv1.png"))); // NOI18N 
     jMenuItem5.setText("System Look&Feel"); 
     jMenuItem5.addActionListener(new java.awt.event.ActionListener() { 
      public void actionPerformed(java.awt.event.ActionEvent evt) { 
       jMenuItem5ActionPerformed(evt); 
      } 
     }); 
     jMenu2.add(jMenuItem5); 

     jMenuBar1.add(jMenu2); 

     setJMenuBar(jMenuBar1); 

     javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 
     getContentPane().setLayout(layout); 
     layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addComponent(pnl_main, javax.swing.GroupLayout.PREFERRED_SIZE, 457, javax.swing.GroupLayout.PREFERRED_SIZE) 
     ); 
     layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addComponent(pnl_main, javax.swing.GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE) 
     ); 

     java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); 
     setBounds((screenSize.width-457)/2, (screenSize.height-300)/2, 457, 300); 
    }// </editor-fold>//GEN-END:initComponents 

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed 
     UIMANAGER_STRING = "de.javasoft.plaf.synthetica.SyntheticaSkyMetallicLookAndFeel"; 
     changeLookandFeel(); 
}//GEN-LAST:event_jMenuItem1ActionPerformed 

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed 
     UIMANAGER_STRING = "de.javasoft.plaf.synthetica.SyntheticaBlueMoonLookAndFeel"; 
     changeLookandFeel(); 
}//GEN-LAST:event_jMenuItem2ActionPerformed 

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed 
     UIMANAGER_STRING = "de.javasoft.plaf.synthetica.SyntheticaBlueIceLookAndFeel"; 
     changeLookandFeel(); 
}//GEN-LAST:event_jMenuItem3ActionPerformed 

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed 
     UIMANAGER_STRING = "de.javasoft.plaf.synthetica.SyntheticaWhiteVisionLookAndFeel"; 
     changeLookandFeel(); 
}//GEN-LAST:event_jMenuItem4ActionPerformed 

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed 
     System.exit(0); 
    }//GEN-LAST:event_jButton2ActionPerformed 

    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed 

     try { 

      UIManager.removeAuxiliaryLookAndFeel(UIManager.getLookAndFeel()); 
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 

      for (int i = 0; i < LookAndFeel.getFrames().length; ++i) { 
       SwingUtilities.updateComponentTreeUI(LookAndFeel.getFrames()[i]); 
      } 

     } catch (Exception ex) { 
      ex.printStackTrace(); 
     } 
    }//GEN-LAST:event_jMenuItem5ActionPerformed 

    /** 
    * @param args the command line arguments 
    */ 
// public static void main(String args[]) { 
//  java.awt.EventQueue.invokeLater(new Runnable() { 
//   public void run() { 
//    new LookAndFeel().setVisible(true); 
//   } 
//  }); 
// } 

    // Variables declaration - do not modify//GEN-BEGIN:variables 
    private javax.swing.JButton jButton1; 
    private javax.swing.JButton jButton2; 
    private javax.swing.JCheckBox jCheckBox1; 
    private javax.swing.JComboBox jComboBox1; 
    private javax.swing.JLabel jLabel1; 
    private javax.swing.JMenu jMenu1; 
    private javax.swing.JMenu jMenu2; 
    private javax.swing.JMenuBar jMenuBar1; 
    private javax.swing.JMenuItem jMenuItem1; 
    private javax.swing.JMenuItem jMenuItem2; 
    private javax.swing.JMenuItem jMenuItem3; 
    private javax.swing.JMenuItem jMenuItem4; 
    private javax.swing.JMenuItem jMenuItem5; 
    private javax.swing.JRadioButton jRadioButton1; 
    private javax.swing.JScrollPane jScrollPane1; 
    private javax.swing.JTextArea jTextArea1; 
    private javax.swing.JTextField jTextField1; 
    private javax.swing.JPanel pnl_main; 
    // End of variables declaration//GEN-END:variables 

    private void changeLookandFeel() { 
     try { 

      UIManager.removeAuxiliaryLookAndFeel(UIManager.getLookAndFeel()); 
      SyntheticaLookAndFeel.setWindowsDecorated(false); 
      UIManager.setLookAndFeel(UIMANAGER_STRING); 

//    for (int i = 0; i < LookAndFeel.getFrames().length; ++i) { 
//    SwingUtilities.updateComponentTreeUI(LookAndFeel.getFrames()[i]); 
//    SwingUtilities.updateComponentTreeUI(this); 
//   } 
      SwingUtilities.updateComponentTreeUI(this); 

     } catch (Exception ex) { 
      try { 
       UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 
} 

MainClass

package jsupport.lookandfeel; 


public class Main { 

    public static void main(String[] args) { 
     new LookAndFeel().setVisible(true); 
    } 
} 
+0

我跟着同一個鏈接。我在上面的評論中甚至提到過它。不起作用! – Anuja

+0

我發現該項目需要seaglass 0.2 jar以及來自鏈接的jar來工作。 – Anuja