Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a program in java with several Jpanels designed; 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? I mean I want to bind properties to my components; and as I changed the property; It's influence reflect on all of jpanels.

like image 985
sajad Avatar asked Jan 26 '26 11:01

sajad


2 Answers

You can use JComponent#putClientProperty(Object key, Object value) and this method could be used for multiple properties in one JComponent

like image 100
mKorbel Avatar answered Jan 28 '26 23:01

mKorbel


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.

Also see the answers to this question: How do I get the default font for Swing JTabbedPane labels?

like image 33
mikera Avatar answered Jan 29 '26 00:01

mikera



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!