So, as we all know, the proper way to change styles for all Components is to subclass LookAndFeel and change the appropriate methods for a specific Component type. But what if I only want to change some of them?
For example, what if I want to have a specific type of Label that is used for page titles. When it’s used in that context I want the font to be bold and to be a bit bigger. What is the proper way to specify those styles for only the page title version of label?
I don’t know that there is a “proper” way to do that, but you can always add a member variable and accessors to get/set, say, an enumerated value in your component that tells what style to use, set it from your editor when creating the components, and then query that style in your LookAndFeel function(s) when that component is being used.
The colours are looked up through the hierarchy. First it is checked, if you set a colour directly on the component, then it fetches the colour from the lookAndFeel.
It is absolutely common to have multiple lookAndFeels, even of the same type. That way they can have different colour settings.
The LookAndFeels are also looked up from each parent until the root is hit.
I found the whole complex too cumbersome and wrote a system, where the component DOM inherits CSS like properties. Have a look at PluginGuiMagic or this thread:
I havent tested this but it might work. Create a globalLookAndFeel that styles your app in whatever default way you want. You could set your labels to whatever default label style you want your labels to have in this look and feel. Then you could subclass this global look and feel (maybe call it SpecialLabel) but only override the label functions and make it special for this type of label.
Then whenever you have a label that needs to be special, you set its look and feel to be the special label look and feel.
In general if you want something simple like a text non-editable label or button with a specific style, I’d say the proper way to do it is to ignore LookAndFeel completely. Just create a super simple label component and override paint, and/or do the same with Button.
you can also let a new class inherit from your custom look and feel and only change the detail that should be a little different in that look and feel instead of rewriting everything or copying a lot of code fragments