简体   繁体   English

java swing组件:绑定属性,如字体和背景颜色

[英]java swing components: binding properties such as font and background color

I have a program in java with several Jpanels designed; 我有一个java程序,设计了几个Jpanels; with certain font and background color for each component on each of my panels. 我的每个面板上的每个组件都有一定的字体和背景颜色。 Is there any clean way to change font of jpanels and components on them? 是否有任何干净的方法来更改它们上的jpanels和组件的字体? I mean I want to bind properties to my components; 我的意思是我想将属性绑定到我的组件; and as I changed the property; 当我改变财产时; It's influence reflect on all of jpanels. 它的影响力反映在所有的jpanel上。

You might want to investigate the use of different Look and Feels . 您可能想要调查使用不同的外观和感觉 This will allow you to change pretty much any properties of your components, and you can even change the loof & feel dynamically at runtime. 这将允许您更改组件的任何属性,甚至可以在运行时动态地更改loof和感觉。

Also see the answers to this question: How do I get the default font for Swing JTabbedPane labels? 另请参阅此问题的答案: 如何获取Swing JTabbedPane标签的默认字体?

您可以使用JComponent#putClientProperty(Object key,Object value) ,此方法可用于一个JComponent多个属性

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

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