自定义外观Nimbus

时间:2016-08-07 00:35:20

标签: java swing user-interface

如何自定义Nimbus外观中的组件图像?我想在photoshop和地方创建图像 在一些Nimbus外观和感觉组件上,这些是我想要改变的组件:

ScrollBar按钮 旋钮滚动条 Thumb ScrollBar ScrollBar Track

谢谢!

1 个答案:

答案 0 :(得分:1)

nimbus的最佳资源是Oracle网站本身here。然而,它主要概述了通过api自定义主题,并允许通过xml以一种有限的方式自定义组件,以引用另一篇文章

要访问和修改您引用的元素,这是一个有用的资源here,然后您可以调用ui管理器以这样的方式应用您希望的任何修改:

UIManager.put("nimbusBase", new Color(...)); UIManager.put("nimbusBlueGrey", new Color(...)); UIManager.put("control", new Color(..

再次提供了一个有用的链接here,详细介绍了你的ui。

关于使用图片修改主题还有很长的帖子 here,但Imo最好的选择是遵循本指南which outlines the xml format for plaf.synth,它允许加载xml纯粹用于可自定义的主题,所以非常理想对于使用photoshop的人:

<style id="buttonStyle">
   <insets top="15" left="20" right="20" bottom="15"/>
   <state>
      <imagePainter method="buttonBackground" path="images/button.png"
        sourceInsets="10 10 10 10"/>
   </state>
</style>
<bind style="buttonStyle" type="region" key="button"/>

获取主题资源:

 private static String synthFile = "buttonSkin.xml";
 private static void initLookAndFeel() {
       // String lookAndFeel = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
       SynthLookAndFeel lookAndFeel = new SynthLookAndFeel();


            try {
                lookAndFeel.load(SynthApplication.class.getResourceAsStream(synthFile),
                                  SynthApplication.class);
                UIManager.setLookAndFeel(lookAndFeel);
            } 

            catch (Exception e) {
                System.err.println("Couldn't get specified look and feel ("
                                   + lookAndFeel
                                   + "), for some reason.");
                System.err.println("Using the default look and feel.");
                e.printStackTrace();
            }

    }

可提供完整的样本here

相关问题