如何在Nimbus外观中自定义组件的图像?我想在photoshop中创建图像,并放置在一些Nimbus外观和感觉组件上,这些是我想要更改的组件:
ScrollBar按钮Knob ScrollBar Thumb ScrollBar ScrollBar Track
谢谢!
发布于 2016-08-07 08:51:06
nimbus的最佳资源是Oracle网站本身的here。然而,它主要概述了通过api自定义主题,并允许通过xml以某种受限的方式使用您的程序自定义组件
对于访问和修改您引用的元素,这是一个有用的资源here,然后您可以调用ui管理器来应用您希望的任何修改,如下所示:
UIManager.put("nimbusBase", new Color(...)); UIManager.put("nimbusBlueGrey", new Color(...)); UIManager.put("control", new Color(..
同样,还有一个有用的链接here,它进入更多的detail.about,将颜色等应用到你的ui上。
也有关于使用图像修改主题的长篇文章 here,但你最好的选择是遵循这个指南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上获得
https://stackoverflow.com/questions/38809870
复制相似问题