开发者

BlackBerry: Overriding paint() vs subpaint()

When making a custom field, what should I consider between overriding the paint() vs subpaint() methods to render custom parts of a field?

My code currently overrides p开发者_如何学Caint(), but I just read the javadoc which suggests to implement the subpaint() method. In my very simple custom fields (like a custom banner with gradient fill), the only difference I can see is that if I override paint(), then I must call super.paint(), but if I override subpaint() then there is no need to call super.subpaint().

I realise that for more advanced customisations, there would be some considerations to take into account, and it is highly likely that one of the approaches might be considered poor practice.

Should I change my base approach (and those in my company) to choose to override subpaint() by default in the future?

(I hope this is not considered a discussion question - that is not my intent - thanks)


subpaint() is really used for Managers, not necessarily a custom Field (yeah, Manager is a Field). It's default implementation is to just loop through its child Fields and issue a paintChild() call on it. paint(), on the other hand, is for the Field to do drawing related to itself. In your case, you should be overriding paint().

So why would you override subpaint()? You would want to if you need child Fields to paint themselves in a certain order. Say that you have a custom Manager that places some Fields on top of each other. If they need to be painted in a certain order, you would override subpaint() to make sure the right Field is "on top." Also, a Manager's paint() will call its subpaint(), something to keep in mind if you override it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜