I have created an gui and i used the seaglasslookandfeel and i have the jar file in my buildpath and i get an exception
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.UIManager;
public class Main {
private JFrame frame;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
UIManager.setLookAndFeel("com.seaglasslookandfeel.SeaGlassLookAndFeel");
开发者_如何学JAVA Main window = new Main();
window.frame.setLocationRelativeTo(null);
window.frame.pack();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public Main() {
initialize();
}
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Panel p=new Panel();
frame.add(p);
}
}
Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError
at sun.reflect.GeneratedConstructorAccessor1.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at com.seaglasslookandfeel.SeaGlassContext.getContext(SeaGlassContext.java:145)
at com.seaglasslookandfeel.ui.SeaGlassPanelUI.getContext(SeaGlassPanelUI.java:154)
at com.seaglasslookandfeel.ui.SeaGlassPanelUI.updateStyle(SeaGlassPanelUI.java:128)
at com.seaglasslookandfeel.ui.SeaGlassPanelUI.propertyChange(SeaGlassPanelUI.java:217)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.awt.Component.firePropertyChange(Unknown Source)
at java.awt.Component.setBackground(Unknown Source)
at javax.swing.JComponent.setBackground(Unknown Source)
at javax.swing.plaf.synth.SynthStyle.installDefaults(Unknown Source)
at com.seaglasslookandfeel.SeaGlassStyleWrapper.installDefaults(SeaGlassStyleWrapper.java:123)
at com.seaglasslookandfeel.SeaGlassStyleWrapper.installDefaults(SeaGlassStyleWrapper.java:113)
at com.seaglasslookandfeel.SeaGlassLookAndFeel.updateStyle(SeaGlassLookAndFeel.java:2286)
at com.seaglasslookandfeel.ui.SeaGlassPanelUI.updateStyle(SeaGlassPanelUI.java:130)
at com.seaglasslookandfeel.ui.SeaGlassPanelUI.propertyChange(SeaGlassPanelUI.java:217)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.awt.Component.firePropertyChange(Unknown Source)
at java.awt.Component.setBackground(Unknown Source)
at javax.swing.JComponent.setBackground(Unknown Source)
at javax.swing.plaf.synth.SynthStyle.installDefaults(Unknown Source)
at com.seaglasslookandfeel.SeaGlassStyleWrapper.installDefaults(SeaGlassStyleWrapper.java:123)
at com.seaglasslookandfeel.SeaGlassStyleWrapper.installDefaults(SeaGlassStyleWrapper.java:113)
at com.seaglasslookandfeel.SeaGlassLookAndFeel.updateStyle(SeaGlassLookAndFeel.java:2286)
at com.seaglasslookandfeel.ui.SeaGlassPanelUI.updateStyle(SeaGlassPanelUI.java:130)
at com.seaglasslookandfeel.ui.SeaGlassPanelUI.propertyChange(SeaGlassPanelUI.java:217)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.awt.Component.firePropertyChange(Unknown Source)
at java.awt.Component.setBackground(Unknown Source)
at javax.swing.JComponent.setBackground(Unknown Source)
at javax.swing.plaf.synth.SynthStyle.installDefaults(Unknown Source)
at com.seaglasslookandfeel.SeaGlassStyleWrapper.installDefaults(SeaGlassStyleWrapper.java:123)
at com.seaglasslookandfeel.SeaGlassStyleWrapper.installDefaults(SeaGlassStyleWrapper.java:113)
at com.seaglasslookandfeel.SeaGlassLookAndFeel.updateStyle(SeaGlassLookAndFeel.java:2286)
at com.seaglasslookandfeel.ui.SeaGlassPanelUI.updateStyle(SeaGlassPanelUI.java:130)
at com.seaglasslookandfeel.ui.SeaGlassPanelUI.propertyChange(SeaGlassPanelUI.java:217)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.awt.Component.firePropertyChange(Unknown Source)
at java.awt.Component.setBackground(Unknown Source)
at javax.swing.JComponent.setBackground(Unknown Source)
at javax.swing.plaf.synth.SynthStyle.installDefaults(Unknown Source)
at com.seaglasslookandfeel.SeaGlassStyleWrapper.installDefaults(SeaGlassStyleWrapper.java:123)
at com.seaglasslookandfeel.SeaGlassStyleWrapper.installDefaults(SeaGlassStyleWrapper.java:113)
at com.seaglasslookandfeel.SeaGlassLookAndFeel.updateStyle(SeaGlassLookAndFeel.java:2286)
at com.seaglasslookandfeel.ui.SeaGlassPanelUI.updateStyle(SeaGlassPanelUI.java:130)
at com.seaglasslookandfeel.ui.SeaGlassPanelUI.propertyChange(SeaGlassPanelUI.java:217)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.awt.Component.firePropertyChange(Unknown Source)
at java.awt.Component.setBackground(Unknown Source)
at javax.swing.JComponent.setBackground(Unknown Source)
at javax.swing.plaf.synth.SynthStyle.installDefaults(Unknown Source)
at com.seaglasslookandfeel.SeaGlassStyleWrapper.installDefaults(SeaGlassStyleWrapper.java:123)
at com.seaglasslookandfeel.SeaGlassStyleWrapper.installDefaults(SeaGlassStyleWrapper.java:113)
at com.seaglasslookandfeel.SeaGlassLookAndFeel.updateStyle(SeaGlassLookAndFeel.java:2286)
at com.seaglasslookandfeel.ui.SeaGlassPanelUI.updateStyle(SeaGlassPanelUI.java:130)
at com.seaglasslookandfeel.ui.SeaGlassPanelUI.propertyChange(SeaGlassPanelUI.java:217)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.awt.Component.firePropertyChange(Unknown Source)
at java.awt.Component.setBackground(Unknown Source)
at javax.swing.JComponent.setBackground(Unknown Source)
at javax.swing.plaf.synth.SynthStyle.installDefaults(Unknown Source)
at com.seaglasslookandfeel.SeaGlassStyleWrapper.installDefaults(SeaGlassStyleWrapper.java:123)
at com.seaglasslookandfeel.SeaGlassStyleWrapper.installDefaults(SeaGlassStyleWrapper.java:113)
at com.seaglasslookandfeel.SeaGlassLookAndFeel.updateStyle(SeaGlassLookAndFeel.java:2286)
at com.seaglasslookandfeel.ui.SeaGlassPanelUI.updateStyle(SeaGlassPanelUI.java:130)
at com.seaglasslookandfeel.ui.SeaGlassPanelUI.propertyChange(SeaGlassPanelUI.java:217)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.awt.Component.firePropertyChange(Unknown Source)
at java.awt.Component.setBackground(Unknown Source)
at javax.swing.JComponent.setBackground(Unknown Source)
at javax.swing.plaf.synth.SynthStyle.installDefaults(Unknown Source)
at com.seaglasslookandfeel.SeaGlassStyleWrapper.installDefaults(SeaGlassStyleWrapper.java:123)
at com.seaglasslookandfeel.SeaGlassStyleWrapper.installDefaults(SeaGlassStyleWrapper.java:113)
at com.seaglasslookandfeel.SeaGlassLookAndFeel.updateStyle(SeaGlassLookAndFeel.java:2286)
at com.seaglasslookandfeel.ui.SeaGlassPanelUI.updateStyle(SeaGlassPanelUI.java:130)
at com.seaglasslookandfeel.ui.SeaGlassPanelUI.propertyChange(SeaGlassPanelUI.java:217)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.awt.Component.firePropertyChange(Unknown Source)
at java.awt.Component.setBackground(Unknown Source)
at javax.swing.JComponent.setBackground(Unknown Source)
at javax.swing.plaf.synth.SynthStyle.installDefaults(Unknown Source)
The program is working on my computer.
I used seaglasslookandfeel-0.1.7.3.jar
library from the Sea Glass Look and Feel for Swing website
I get the following output
Here is the code
import java.awt.EventQueue;
import java.awt.Panel;
import javax.swing.JFrame;
import javax.swing.UIManager;
public class SeaGlassLNFTest {
private JFrame frame;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
UIManager.setLookAndFeel("com.seaglasslookandfeel.SeaGlassLookAndFeel");
SeaGlassLNFTest window = new SeaGlassLNFTest();
window.frame.setLocationRelativeTo(null);
//window.frame.pack();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public SeaGlassLNFTest(){
initialize();
}
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Panel p = new Panel();
frame.add(p);
}
}
Although I have added java.awt.Panel
to a javax.swing.JFrame
, it should be avoided. Here is an article mentioning the reasons of what to expect when mixing heavyweight and lightweight components.
Swing Look and Feel is for Swing(lightweight) components and not applicable to heavyweight components.
精彩评论