zoukankan      html  css  js  c++  java
  • 做出漂亮的Java界面--substance.jar的使用

    1.将substance.jar添加到类路径中
    2.将下列代码添加到你的程序的主执行类的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!");
            }

    这个地方主要介绍一下关于使用substance.jar包装程序时对界面效果的几个方面的设置,主要要主题,皮肤,按钮类型,水印,边框渲染,渐变渲染与标题栏渲染.

    共有22种皮肤,69种主题。

    1. 下载下来substance.jar包后,解压JAR文件,可以看到在“org/jvnet/substance/skin”下有下面这些皮肤(以LookAndFeel.class结尾的文件)。

    SubstanceAutumnLookAndFeel.class

    SubstanceBusinessBlackSteelLookAndFeel.class

    SubstanceBusinessBlueSteelLookAndFeel.class

    SubstanceBusinessLookAndFeel.class

    SubstanceChallengerDeepLookAndFeel.class

    SubstanceCremeLookAndFeel.class

    SubstanceEmeraldDuskLookAndFeel.class

    SubstanceFieldOfWheatLookAndFeel.class

    SubstanceGreenMagicLookAndFeel.class

    SubstanceMagmaLookAndFeel.class

    SubstanceMangoLookAndFeel.class

    SubstanceMistAquaLookAndFeel.class

    SubstanceMistSilverLookAndFeel.class

    SubstanceModerateLookAndFeel.class

    SubstanceNebulaBrickWallLookAndFeel.class

    SubstanceNebulaLookAndFeel.class

    SubstanceOfficeBlue2007LookAndFeel.class

    SubstanceOfficeSilver2007LookAndFeel.class

    SubstanceRavenGraphiteGlassLookAndFeel.class

    SubstanceRavenGraphiteLookAndFeel.class

    SubstanceRavenLookAndFeel.class

    SubstanceSaharaLookAndFeel.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

    SubstanceBottleGreenTheme.class

    SubstanceBrownTheme.class

    SubstanceCharcoalTheme.class

    SubstanceColorBlindTheme.class

    SubstanceComplexTheme.class

    SubstanceCremeTheme.class

    SubstanceDarkVioletTheme.class

    SubstanceDesertSandTheme.class

    SubstanceDeuteranopiaTheme.class

    SubstanceEbonyTheme.class

    SubstanceHueShiftTheme.class

    SubstanceInvertedTheme.class

    SubstanceJadeForestTheme.class

    SubstanceLightAquaTheme.class

    SubstanceLimeGreenTheme.class

    SubstanceMixBiTheme.class

    SubstanceMixTheme.class

    SubstanceNegatedTheme.class

    SubstanceOliveTheme.class

    SubstanceOrangeTheme.class

    SubstanceProtanopiaTheme.class

    SubstancePurpleTheme.class

    SubstanceRaspberryTheme.class

    SubstanceSaturatedTheme.class

    SubstanceSepiaTheme.class

    SubstanceShadeTheme.class

    SubstanceSteelBlueTheme.class

    SubstanceSunGlareTheme.class

    SubstanceSunsetTheme.class

    SubstanceTerracottaTheme.class

    SubstanceTheme$1$1.class

    SubstanceTheme$1.class

    SubstanceTheme$10.class

    SubstanceTheme$11.class

    SubstanceTheme$12.class

    SubstanceTheme$13.class

    SubstanceTheme$14.class

    SubstanceTheme$15.class

    SubstanceTheme$16.class

    SubstanceTheme$17.class

    SubstanceTheme$18.class

    SubstanceTheme$19.class

    SubstanceTheme$2.class

    SubstanceTheme$20.class

    SubstanceTheme$21.class

    SubstanceTheme$22.class

    SubstanceTheme$23.class

    SubstanceTheme$24.class

    SubstanceTheme$25.class

    SubstanceTheme$26.class

    SubstanceTheme$27.class

    SubstanceTheme$28.class

    SubstanceTheme$3.class

    SubstanceTheme$4.class

    SubstanceTheme$5.class

    SubstanceTheme$6.class

    SubstanceTheme$7.class

    SubstanceTheme$8.class

    SubstanceTheme$9.class

    SubstanceTheme$ThemeKind.class

    SubstanceTheme.class

    SubstanceTintTheme.class

    SubstanceToneTheme.class

    SubstanceTritanopiaTheme.class

    SubstanceUltramarineTheme.class

    SubstanceWrapperTheme.class

     

    改变界面的默认主题也很简单,只需要加上以下代码就可以了(不过貌似5.0以上没有这个方法了,且substance下也没有theme文件夹了)。另外5.0版本以上必须将这些语句置于

    java.awt.EventQueue.invokeLater(new Runnable() {

    public void run() {

       //此处设置皮肤和主题

    });

    的run方法中,否则会出错。

    SubstanceLookAndFeel.setCurrentTheme("org.jvnet.substance.theme.SubstanceDarkVioletTheme");

    另外如果想让整体界面变得协调,最好设置容器窗体的DefaultLookAndFeelDecorated属性为true。

    JFrame.setDefaultLookAndFeelDecorated(true);

    JDialog.setDefaultLookAndFeelDecorated(true);

     

    当然除了设置皮肤和主题外,还可以设置按钮、水印、选项卡、滑动条以及水印、字体、标题等的观感。具体的可以查看substanceorgjvnetsubstance目录。方法同上面讲的一样。

  • 相关阅读:
    poj 2947 Widget Factory 夜
    poj 1222 EXTENDED LIGHTS OUT 夜
    poj 3440 Coin Toss 夜
    poj 1166 The Clocks 夜
    poj 3270 Cow Sorting 夜
    poj 3071 Football 夜
    poj 2409 Let it Bead 夜
    poj 1141 Brackets Sequence 夜
    hdu 4311 Meeting point1 夜
    poj 1026 Chipher 夜
  • 原文地址:https://www.cnblogs.com/IntelligentBrain/p/5111308.html
Copyright © 2011-2022 走看看