可以使用substance改变界面的皮肤和主题,让Java制作的界面“炫”起来
可以下载substance.jar文件
http://insubstantial.github.io/insubstantial/substance/learn.html
在代码中你可以用:
static { try { try { UIManager.setLookAndFeel(new SubstanceLookAndFeel()); } catch (UnsupportedLookAndFeelException ex) { System.out.println(ex.getMessage()); } } catch (Exception ex) { System.out.println(ex.getMessage()); } //设置皮肤 // SubstanceSaharaLookAndFeel.setSkin(new CremeSkin()); SubstanceSaharaLookAndFeel.setSkin(new AutumnSkin()); //SubstanceSaharaLookAndFeel.setCurrentButtonShaper(new StandardButtonShaper()); //SubstanceSaharaLookAndFeel.setFontPolicy(new DefaultMacFontPolicy()); //设置水印 SubstanceLookAndFeel.setCurrentWatermark(new SubstanceBubblesWatermark()); //设置主题 // SubstanceLookAndFeel.setCurrentTheme(new SubstanceCremeTheme()); SubstanceLookAndFeel.setCurrentTheme(new SubstanceLightAquaTheme()); // SubstanceLookAndFeel.setCurrentTheme(new SubstanceOliveTheme()); // SubstanceLookAndFeel.setCurrentTheme(new SubstanceJadeForestTheme()); //设置题头 SubstanceLookAndFeel.setCurrentTitlePainter(new Glass3DTitlePainter());
下载下来substance.jar包后,解压JAR文件,可以看到在“org/jvnet/substance/skin”下有下面这些皮肤(以LookAndFeel.class结尾的文件)。
共有22种皮肤,69种主题,自己设置
我给你个地址吧,上面全是开源的外观,可以直接拿来用,很方便
http://www.open-open.com/61.htm
http://www.iteye.com/problems/70945
http://www.iteye.com/topic/702804
http://www.iteye.com/topic/726318
http://www.iteye.com/topic/714669
java LookAndFeel 美化 Substance使用
改变外观,似乎是一个很麻烦的事情,幸运的是在swing里,我们只需要简单的一行代码就可以改变
UIManager.setLookAndFeel(new LookAndFeel());
比如:
UIManager.setLookAndFeel(new QuaquaLookAndFeel());
我们还可以通过
UIManager.setLookAndFeel(String s);
来改变外观,其中,s是表示该外观的路径,比如
UIManager.setLookAndFeel(
"org.fife.plaf.OfficeXP.OfficeXPLookAndFeel");
另外,如果该Look And Feel类对窗口的边框还有修饰的话,还可以通过
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
这样一来,窗口就会采用该外观特制的边框.
最出名的当属Substance。官网:http://insubstantial.github.io/insubstantial/substance/
使用,将Substance.jar引入到lib中,然后在main中:
try { UIManager.setLookAndFeel(new SubstanceLookAndFeel()); JFrame.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true); SubstanceLookAndFeel.setCurrentTheme(new SubstanceTerracottaTheme()); // SubstanceLookAndFeel.setSkin(new EmeraldDuskSkin()); // SubstanceLookAndFeel.setCurrentButtonShaper(new ClassicButtonShaper()); // SubstanceLookAndFeel.setCurrentWatermark(new SubstanceBubblesWatermark()); // SubstanceLookAndFeel.setCurrentBorderPainter(new StandardBorderPainter()); // SubstanceLookAndFeel.setCurrentGradientPainter(new StandardGradientPainter()); // SubstanceLookAndFeel.setCurrentTitlePainter(new FlatTitePainter()); } catch (Exception e) { System.err.println("Something went wrong!"); }
public static void main(String[] args) { // 装载可选择的主题 try { //设置外观 UIManager.setLookAndFeel(new SubstanceBusinessBlackSteelLookAndFeel()); JFrame.setDefaultLookAndFeelDecorated(true); //设置主题 SubstanceLookAndFeel.setCurrentTheme(new SubstanceEbonyTheme()); //设置按钮外观 SubstanceLookAndFeel.setCurrentButtonShaper(new ClassicButtonShaper()); //设置水印 SubstanceLookAndFeel.setCurrentWatermark(new SubstanceBinaryWatermark()); //设置边框 SubstanceLookAndFeel.setCurrentBorderPainter(new StandardBorderPainter()); //设置渐变渲染 SubstanceLookAndFeel.setCurrentGradientPainter(new StandardGradientPainter()); //设置标题 SubstanceLookAndFeel.setCurrentTitlePainter(new FlatTitlePainter()); } catch (Exception e) { System.out.println(e.getMessage()); } }
这个地方主要介绍一下关于使用substance.jar包装程序时对界面效果的几个方面的设置,主要让
主题,皮肤,按钮类型,水印,边框渲染,渐变渲染与标题栏渲染.
他们都可以通过 SubstanceLookAndFeel类的静态方法 setCurrentXXX(XXX)来完成设置,其中对皮肤的设置稍有不同,使用静态方法setSkin(),没有Current这个单词,这主要是由于一个皮肤对象中已经包含了所有其他的如主题,水印,按钮类型的设置.另外注意,所以这些类型并没有作为一个类的字段来出现,而且他们各处单独是一个类,所以都需要通过new来创建他们的实例.其中除了皮肤,按钮,标题栏,其他的对象都是以Substance+名称+类型 来命名的.(主题是皮肤的一部分)
共有22种皮肤,69种主题。
1. 下载下来substance.jar包后,解压JAR文件,可以看到在“org/jvnet/substance/skin”下有下面这些皮肤(以LookAndFeel.class结尾的文件)。
SubstanceAutumnLookAndFeel.class
SubstanceBusinessBlackSteelLookAndFeel.class
SubstanceBusinessBlueSteelLookAndFeel.class
SubstanceBusinessLookAndFeel.class
要使用上述皮肤很简单,只要在main函数中调用下面代码即可:
//主要设置皮肤、主题还有按钮、水印、选项卡、滑动条以及水印等
//UIManager.setLookAndFeel("org.jvnet.substance.skin.SubstanceBusinessLookAndFeel");
//UIManager.setLookAndFeel("org.jvnet.substance.skin.SubstanceOfficeSilver2007LookAndFeel");
//UIManager.setLookAndFeel("org.jvnet.substance.skin.SubstanceSaharaLookAndFeel");
//UIManager.setLookAndFeel("org.jvnet.substance.skin.SubstanceOfficeBlue2007LookAndFeel");
UIManager.setLookAndFeel("org.jvnet.substance.skin.SubstanceBusinessBlackSteelLookAndFeel");
2. org/jvnet/substance/theme 下有可用主题:
SubstanceAquaTheme.class
SubstanceBarbyPinkTheme.class
SubstanceBlendBiTheme.class
............
疑问:
UIManager.setLookAndFeel(new SubstanceLookAndFeel());
这里的SubstanceLookAndFeel不是一个skin类,我在skin下找不到这个类。
参考:http://hi.baidu.com/jxqlovejava/item/fe3116cd169593d0ee183b37
http://hitzsf.blog.163.com/blog/static/34668206201172110510740/
http://blog.csdn.net/zhenshiyiqie/article/details/8425923
http://www.iteye.com/topic/394314