本站首页    管理页面    写新日志    退出


«December 2025»
123456
78910111213
14151617181920
21222324252627
28293031


公告
本博客在此声明所有文章均为转摘,只做资料收集使用。并无其他商业用途。

我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:
日志总数:210
评论数量:205
留言数量:-19
访问次数:928808
建立时间:2007年5月10日




[界面和模板语言]用Look And Feel打造绚丽的界面外观[转]
文章收藏,  网上资源,  软件技术,  电脑与网络

李小白 发表于 2007/7/19 10:04:36

lhwork 发表于 2006-10-23 10:02:14 虽然我们知道,一个桌面应用程序的好坏,和它的性能,功能有着很大关系,然而,对于大多数坐在电脑前的用户而言,他们的标准往往是: 绚丽的外观MVC设计下的的SWING自然没有忽视这一点,通过对UIManager的设置,我们可以很容易的改变应用程序的外观,也就是LOOK AND FEEL一.如何设置look and feel:改变外观,似乎是一个很麻烦的事情,幸运的是在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);这样一来,窗口就会采用该外观特制的边框二.一些比较帅气的look and feelswing自带提供了几种look and feel类,不过,这显然是不够的,下面,就让我们看看第三方都提供了些什么酷酷的外观咯:1.Substance    这个项目的目的是提供一个流行的外观(look & feel)。这个外观(look & feel)联合了Windows XP和MacOS 10.4最好的特性并且需要JDK 5.0以上。    500)this.width=500'>500)this.width=500'>500){this.resized=true;this.style.width=500;}">    将窗口的边框替换成Substance特定边框后,我们还可以通过点击其左上角的小方块来手工配制其外观,可以配制的有主题,水印,按钮形状,渐变情况,看,这个蝴蝶形状的button多酷!500)this.width=500'>500)this.width=500'>500){this.resized=true;this.style.width=500;}">2.Smooth    提供了改进型的windows和metal风格的外观风格500)this.width=500'>500)this.width=500'>500){this.resized=true;this.style.width=500;}">3.Office&windos   提供了仿照Xp,Office2003和VS的外观风格500)this.width=500'>500)this.width=500'>500){this.resized=true;this.style.width=500;}" dragover="true">4.其他   在网站上罗列如今较为流行的外观类,大家有兴趣可以去研究一下咯^_^    http://www.open-open.com/61.htm三.使用方法将下列jar文件拷贝到你的程序的classpath中,然后将下列代码段加入到你main函数中http://210.42.106.102/bbs/viewth ... &extra=page%3D1(注,其实我在别的文章中给出了一个例子,参见用java打造任意形状窗口一文中的的代码) 1.substance look and feel:   try {                        UIManager.setLookAndFeel(new SubstanceLookAndFeel());                        UIManager.put("swing.boldMetal", false);                        if (System.getProperty("substancelaf.useDecorations") == null) {                                JFrame.setDefaultLookAndFeelDecorated(true);                                JDialog.setDefaultLookAndFeelDecorated(true);                        }                        System.setProperty("sun.awt.noerasebackground", "true");                        SubstanceLookAndFeel.setCurrentTheme(new SubstanceLightAquaTheme());//设置当前的主题风格,同样我 们还可以设置当前的按钮形状,水印风格等等                } catch (Exception e) {                        System.err.println("Oops!  Something went wrong!");                }    2.smooth look and feel             try {                        UIManager.setLookAndFeel(new SmoothLookAndFeel());                       // UIManager.put("swing.boldMetal", false);                } catch (Exception e) {                        System.err.println("Oops!  Something went wrong!");                }3.   office/winxp/VisualStudio 2005 look and feel      try {                    UIManager.setLookAndFeel("org.fife.plaf.Office2003.Office2003LookAndFeel");                    //UIManager.setLookAndFeel("org.fife.plaf.OfficeXP.OfficeXPLookAndFeel");                    //UIManager.setLookAndFeel("org.fife.plaf.VisualStudio2005.VisualStudio2005LookAndFeel");                   // UIManager.put("swing.boldMetal", false);                } catch (Exception e) {                        System.err.println("Oops!  Something went wrong!");                }


阅读全文(1857) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.559 second(s), page refreshed 144803980 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号