Substance效果查看器

花了些时间做了个,Substance效果查看器,方便选择使用。



* 须使用substance.jar.




import javax.swing.*;
import java.awt.EventQueue;
import java.awt.event.*;
import java.util.*;
import org.jvnet.substance.skin.*;






public class NewClass 
{

   public static void main(String[] args)
   {
      JFrame.setDefaultLookAndFeelDecorated(true);
     JDialog.setDefaultLookAndFeelDecorated(true);

        EventQueue.invokeLater(new Runnable() {
       public void run() {
           PlafFrame frame = new PlafFrame();
           frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
           frame.setVisible(true);
            }
        });
    }
}


class PlafFrame extends JFrame{
    public PlafFrame(){
        setTitle("dddd");
        setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);

        buttonPanel = new JPanel();
        skinmapsize=skinmap.size();
        for (int i=0;i<skinmapsize;i++){
            Map.Entry entry = (Map.Entry)keyvaluepair.next();
            String justname= (String)entry.getKey();
            SkinInfo value=(SkinInfo)entry.getValue();
            String classname=value.getClassName();


            makeButton(classname.substring(0,classname.length()-4).substring(25),classname);
        }   
        add(buttonPanel);
    }

    void makeButton(String name,final String laf){
        JButton button=new JButton(name);
        buttonPanel.add(button);

          button.addActionListener(new ActionListener()
         {
            public void actionPerformed(ActionEvent event)
            {
               // button action: switch to the new look and feel
               try
               {
                  UIManager.setLookAndFeel("org.jvnet.substance.skin.Substance"+laf.substring(0,laf.length()-4).substring(25)+"LookAndFeel");

                  SwingUtilities.updateComponentTreeUI(PlafFrame.this);
               }
               catch (Exception e)
               {
                  e.printStackTrace();
               }
            }
         });
   
    }

    private Map skinmap=org.jvnet.substance.SubstanceLookAndFeel.getAllSkins();
    private int skinmapsize;
    private Iterator keyvaluepair=skinmap.entrySet().iterator();
    private JPanel buttonPanel;
    private int DEFAULT_WIDTH = 400;
    private int DEFAULT_HEIGHT = 300;

}

你可能感兴趣的:(java,swing)