SWT 用户控件设计决策
假设问题:
为了制作自定义复合小部件,我必须将 Composite 子类化,这个 SWT 设计决策怎么样?这真的明智吗?
如果 SWT 有一个像 Win Forms 之类的 UserControl 类不是更好吗?
当我对 Composite 进行子类化时,我的自定义小部件将获得 Composite 接口,即使它不打算被客户端用作 Composite。这有点糟糕。对于某些 SWT 小部件(例如 Spinner)也是如此。
有没有好的办法解决这个问题?
而且,最有趣的是:有人知道这个设计决定的动机吗?
Hypothetical question:
What about this SWT design decision that to make a custom compound widget I have to subclass Composite? Is that really wise?
Wouldn't it be better if SWT had a UserControl class like in Win Forms or something?
When I subclass Composite my custom widget get the Composite interface, even if it is not intended to be used as a Composite by clients. That's kind of bad. The same is true for some SWT widgets, like Spinner.
Is there a good way around this?
And, most interesting: Do anyone know the motivation for this design decision?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以查看 org.eclipse.swt.custom.CCombo 的源代码,了解 SWT 如何在内部处理此问题,因为
CCombo
扩展自Composite< /代码>。以下是他们处理
setLayout()
的方式,例如:You could look at the source code for
org.eclipse.swt.custom.CCombo
to see how SWT deals with this problem internally, asCCombo
extends fromComposite
. Here's how they handlesetLayout()
, for example:您可以创建自己的
NonCompositeUserControl
类:You could create your own
NonCompositeUserControl
class: