Styling: support component type specific styles #417
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PRs #341 and #388 added basic styling and style classes E.g.
which is comparable to what can be done in HTML:
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:
or in Java code:
This style is applied to all scrollpanes in the application.
This is comparable to what can be done in CSS. E.g.
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 inJComboBox
;JTextField
in editableJComboBox
) 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.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 theEmptyBorder
and anUnknownStyleException
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?