Styling: support component type specific styles
PRs #341 and #388 added basic styling and style classes E.g.
mySlider.putClientProperty( "FlatLaf.style", "thumbColor: #f00" );
or
mySlider.putClientProperty( "FlatLaf.styleClass", "myclass" );
which is comparable to what can be done in HTML:
<p style="background: #f00">
or
<p class="myclass">
This PR is the next step and adds support for component type specific styles, which are applied to all components of that type.
E.g. in FlatLaf properties file:
[style]ScrollPane = focusedBorderColor: #f00
or in Java code:
UIManager.put( "[style]ScrollPane", "focusedBorderColor: #f00" );
This style is applied to all scrollpanes in the application.
This is comparable to what can be done in CSS. E.g.
p {
background: #f00;
}
Issues/problems
Because those style rules are applied to all components of a type within the application, this may cause some side effects or unwanted changes.
E.g. some components internally use other components (JButton for arrow button in JComboBox; JTextField in editable JComboBox) and those internal components are changed too.
Some styling properties are applied to borders (e.g. see fields in class FlatBorder annotated with @Styleable). When the border of a component is removed/changed then those style properties no longer can applied and exceptions are logged.
UIManager.put( "[style]ScrollPane", "focusedBorderColor: #f00" );
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBorder( BorderFactory.createEmptyBorder() );
The above code initially works because the style rule is applied within the constructor and the border is changed after it, but if you switch the theme, the style rule focusedBorderColor: #f00 can not applied to the EmptyBorder and an UnknownStyleException is logged.
FlatLaf is very strict (at the moment) and logs any style property that can not applied. CSS on the other side simply ignores unknown styles...
CC @ebourg (issue #412); @Chrriis (issue #117); @orange451 (issue #340)
I'm a little bit undecided whether this PR is a good idea, or do more harm than good?
My original issue was to use a FlatLaf theme but to have a custom component somewhere. I am not sure which use case the feature you are presenting is trying to solve. Is it a way to have in effect multiple FlatLaf themes? Or is it a way to alter a theme after it is loaded, but then why not alter the theme?