java.lang.NoClassDefFoundError: sun/swing/plaf/synth/SynthUI

爷,独闯天下 提交于 2019-11-29 18:25:57

The best way to test the compatibility is to check whether the code is working with Java 6 (If you are using any IDE like eclipse of Intellij they have the option of compiling file with lower Java version).

From the error it seems that at run-time it is not able to find the Class, or the path where it is located. You can try java -cp to specify the path.

@Anuja U Follow this link

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);
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!