gpt4 book ai didi

java - 自定义外观 Nimbus

转载 作者:行者123 更新时间:2023-12-01 09:37:04 24 4
gpt4 key购买 nike

如何自定义 Nimbus 外观中组件的图像?我想在 Photoshop 中创建图像并放置在一些 Nimbus 外观和感觉组件上,这些是我想要更改的组件:

滚动条按钮旋钮滚动条拇指滚动条滚动条轨道

谢谢!

最佳答案

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

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

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

再次有一个有用的链接 here这是更详细的内容。关于将颜色等应用到您的用户界面。

还有很长的帖子 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

关于java - 自定义外观 Nimbus,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38809870/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com