zoukankan      html  css  js  c++  java
  • 用各种look and feel打造swing界面

     用各种look and feel打造swing界面

    来源:http://www.java3z.com/cwbwebhome/article/article2/2351.html?id=979

    虽然我们知道,一个桌面应用程序的好坏,和它的性能,功能有着很大关系,然而,对于大多数坐在电脑前的用户而言,他们的标准往往是: 绚丽的外观 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 feel
    swing自带提供了几种look and feel类,不过,这显然是不够的,下面,就让我们看看第三方都提供了些什么酷酷的外观咯:

    1.Substance
        这个项目的目的是提供一个流行的外观(look & feel)。这个外观(look & feel)联合了Windows XP和MacOS 10.4最好的特性并且需要JDK 5.0以上。
       




        将窗口的边框替换成Substance特定边框后,我们还可以通过点击其左上角的小方块来手工配制其外观,可以配制的有
    主题,水印,按钮形状,渐变情况,看,这个蝴蝶形状的button多酷!





    2.Smooth
        提供了改进型的windows和metal风格的外观风格




       提供了仿照Xp,Office2003和VS的外观风格




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

    相关文章:

    java程序发布之jre篇 java程序打包成exe可执行安装包以便安装程序

    java.lang.Class.getResource()这哥个方法主要是做什么用

  • 相关阅读:
    Codeforces 689A Mike and Cellphone
    栈的一些基本操作
    Intersecting Lines POJ 1269
    Segments POJ 3304 直线与线段是否相交
    Toy Storage POJ 2398
    CF471D MUH and Cube Walls
    P 3396 哈希冲突 根号分治
    P1445 [Violet]樱花
    P6810 「MCOI-02」Convex Hull 凸包
    P3455 [POI2007]ZAP-Queries
  • 原文地址:https://www.cnblogs.com/langtianya/p/2631300.html
Copyright © 2011-2022 走看看