问题
I am using Seaglass Look and Feel for my Java Swings code. But I keep getting this error.
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
I did a bit of research and found that Seaglass does not work with Java 7 (my current version) and hence the issue. But I am looking a way to make it work or if anyone has any demo that works perfectly with Java 7 version, it would be very helpful.
My code:
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();
}
}
The Jars that I am using
回答1:
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.
回答2:
@Anuja U Follow this link
Linkpackage 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);
}
}
来源:https://stackoverflow.com/questions/34527035/java-lang-noclassdeffounderror-sun-swing-plaf-synth-synthui