【发布时间】:2016-08-07 00:35:19
【问题描述】:
如何在 Nimbus 外观和感觉中自定义组件的图像?我想在 Photoshop 中创建图像并放置 在一些 Nimbus 外观和感觉组件上,这些是我想要更改的组件:
滚动条按钮 旋钮滚动条 拇指滚动条 滚动条轨道
谢谢!
【问题讨论】:
标签: java swing user-interface
如何在 Nimbus 外观和感觉中自定义组件的图像?我想在 Photoshop 中创建图像并放置 在一些 Nimbus 外观和感觉组件上,这些是我想要更改的组件:
滚动条按钮 旋钮滚动条 拇指滚动条 滚动条轨道
谢谢!
【问题讨论】:
标签: java swing user-interface
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 关于使用图像修改主题,但我最好的选择是遵循本指南 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
【讨论】: