Insets for custom Synth look and feel
I'm implementing a custom Look & Feel 开发者_开发问答using Synth for my application - basically providing custom versions of SynthStyle, SynthPainter and SynthStyleFactory.
I am not using any XML, i.e. everything is done through the Java API. In general this is working just fine.
The best way to set appropriate insets is however proving a little tricky. I can see various options:
- Override getInsets for SynthStyle to return specific insets for each Region
- Apply a border to components using SynthStyle.installDefaults
- Set all insets to (0,0,0,0) and compensate in the painting methods
- Create new ComponentUI delegates
What would be the best approach and why?
Did you come to a decision on this yet? Here's my opinion on things...
Overriding getInsets()
looks like a nice solution if you have a simple style with a small number of contexts. It should help keep insets consistent throughout your GUI with only one point of change needed.
Applying an empty border to components seems a little hackish for this purpose. If you need to apply a custom border to a component then you might inadvertently remove the empty border unless you override the setBorder()
methods to use a compound border.
Setting all insets to 0 is unnecessary since they start at 0 already... I would be very scared at the thought of rewriting paint methods! That's generally done for adding finishing touches to components, not re-defining their entire boundaries.
I'm not entirely sure how creating a new ComponentUI
would help, since that's mainly to do with sizing and painting (like the above).
I would try out option 1 first since it will have a global effect on your application, and then start working out what exceptions and contexts you want to put into it.
精彩评论