简体   繁体   English

将摆动颜色延伸到自定义组件

[英]Extend swing colors to custom components

Implementing swing applications, often you realize class of components that should have a coherent look. 实现swing应用程序,通常你会意识到应该具有连贯外观的组件类。
Example: Mypanel that extends JPanel and represents an applicative object and thus having a yellow background with a darker yellow border line. 示例:扩展JPanel并表示应用对象的Mypanel ,因此具有黄色背景和深黄色边框线。
Is it possible to leverage the swing color management? 可以利用摇摆色管理吗?
My idea is to put my colors into UIManager.getLookAndFeelDefaults map and then bind them to the component somehow. 我的想法是将我的颜色放入UIManager.getLookAndFeelDefaults地图中,然后以某种方式将它们绑定到组件。
This "somehow" is the question: how to do that in the simplest form? 这个“不知何故”的问题是:如何以最简单的形式做到这一点?

Something like this should work if you want to customise just a few components: 如果你想自定义几个组件,这样的东西应该工作:

// Specify the colors
UIDefaults uiDef = new UIDefaults();
uiDef.put("Panel.background", Color.BLUE);

// Use the colors on a specific component
JPanel panel = new JPanel();
panel.putClientProperty("Nimbus.Overrides", uiDef);
SwingUtilities.updateComponentTreeUI(panel);

See the Nimbus defaults for key-names and default colors and painters. 有关键名和默认颜色以及画家的信息,请参阅Nimbus默认值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM