外观和感觉seaglass外观和感觉异常

时间:2011-05-15 13:19:26

标签: java swing

我创建了一个gui,我使用了seaglasslookandfeel,我的buildpath中有jar文件,我得到了一个异常

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");
                    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)

1 个答案:

答案 0 :(得分:2)

该程序正在我的电脑上运行。

我使用了Sea Glass Look and Feel for Swing website

中的seaglasslookandfeel-0.1.7.3.jar

我得到以下输出

output screenshot

这是代码

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);
        }
}

虽然我已将java.awt.Panel添加到javax.swing.JFrame,但应该避免。这是article提到混合重量级和轻量级组件时会发生什么的原因。

Swing Look and Feel适用于Swing(轻量级)组件,不适用于重量级组件。