Swing免费皮肤Substance的使用

关键词:Swing换肤,Substance,免费皮肤

Swing是可以换肤的,这个大家都知道,不过没有多少人会真正去编写代码来更换Swing的皮肤,因为那个工作量太大了,几乎像一个项目一样浩大,所以现在的免费皮肤并不多,这里给大家推荐几种 免费的Swing皮肤

今天先介绍 Substance,Substance皮肤的使用非常简单,导入jar包,然后指名皮肤就可以使用了。官方网址是: https://substance.dev.java.net/
1.导入Jar包
使用Substance皮肤,只要引用substance.jar和trident.jar就可以了。如果您还想编辑它的源码,就需要使用它规定的其他jar包。具体的下载资源,会在下面提供。

2.使用皮肤
皮肤的使用
public class Index {

	public static void main(String[] args) {

		JFrame.setDefaultLookAndFeelDecorated(true);
		JDialog.setDefaultLookAndFeelDecorated(true);

		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				SubstanceLookAndFeel.setSkin(new BusinessBlackSteelSkin());
				try {
					final IndexFrame frame = new IndexFrame();
					frame.setTitle("SubstanceLookAndFeel");
					frame.setVisible(true);

					frame.setSize(600, 400);
					frame.setLocationRelativeTo(frame.getOwner());
					frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
					frame.setIconImage(Toolkit.getDefaultToolkit().createImage(
							IndexFrame.class.getResource("icon.png")));

					frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
					frame.addWindowListener(new WindowAdapter() {
						public void windowClosing(WindowEvent e) {
							int flag = JOptionPane.showConfirmDialog(frame,
									"Sure to close?", "Care!",
									JOptionPane.YES_NO_OPTION,
									JOptionPane.INFORMATION_MESSAGE);
							if (JOptionPane.YES_OPTION == flag) {
								System.exit(0);
							} else {
								return;
							}
						}
					});

				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
}

需要注意的是Substance必须在一个线程中启动(SwingUtilities.invokeLater),否则程序会提示错误。完整的程序见第四部分:相关资源
Substance总共定义了27种皮肤,分别是:
org.pushingpixels.substance.api.skin.AutumnSkin,
org.pushingpixels.substance.api.skin.BusinessSkin,
org.pushingpixels.substance.api.skin.BusinessBlackSteelSkin,
org.pushingpixels.substance.api.skin.BusinessBlueSteelSkin,
org.pushingpixels.substance.api.skin.ChallengerDeepSkin,
org.pushingpixels.substance.api.skin.CremeSkin,
org.pushingpixels.substance.api.skin.CremeCoffeeSkin,
org.pushingpixels.substance.api.skin.DustSkin,
org.pushingpixels.substance.api.skin.DustCoffeeSkin,
org.pushingpixels.substance.api.skin.EmeraldDuskSkin,
org.pushingpixels.substance.api.skin.GeminiSkin,
org.pushingpixels.substance.api.skin.GraphiteSkin,
org.pushingpixels.substance.api.skin.GraphiteAquaSkin,
org.pushingpixels.substance.api.skin.GraphiteGlassSkin,
org.pushingpixels.substance.api.skin.MagellanSkin,
org.pushingpixels.substance.api.skin.MarinerSkin,
org.pushingpixels.substance.api.skin.MistAquaSkin,
org.pushingpixels.substance.api.skin.MistSilverSkin,
org.pushingpixels.substance.api.skin.ModerateSkin,
org.pushingpixels.substance.api.skin.NebulaSkin,
org.pushingpixels.substance.api.skin.NebulaBrickWallSkin,
org.pushingpixels.substance.api.skin.OfficeBlack2007Skin,
org.pushingpixels.substance.api.skin.OfficeBlue2007Skin,
org.pushingpixels.substance.api.skin.OfficeSilver2007Skin,
org.pushingpixels.substance.api.skin.RavenSkin,
org.pushingpixels.substance.api.skin.SaharaSkin

大家可以根据自己需要选择不同的皮肤。

3.运行效果:




4.相关资源
4.1 substance.jar和trident.jar
http://www.kutoku.info/images/java/101025/lookandfeel.zip
4.2 Substance完整jar
http://www.kutoku.info/images/java/101025/lib.zip
4.3 完整例子
http://www.kutoku.info/images/java/101025/ZakiSoft.zip

你可能感兴趣的:(多线程,.net,工作,swing)