java swing:自定义所有内容 - 子类 jcomponent 或 jpanel 或...?

发布于 2024-07-13 05:52:42 字数 191 浏览 2 评论 0原文

你好 - 快速 - 与 JPanel 相比,子类化 JComponent 是否有任何危害/价值?

对我来说,如果我自己画画和画画,它们看起来几乎是一样的。 该对象不会有任何子对象,但是似乎有一个在 JComponent 上对 JPanel 进行子类化的偏好 - 只是寻找关于为什么这可能是这样的意见......

Thx :-)

Hiya - quick one - is there any harm / value in subclassing JComponent as compared to JPanel ?

To me they pretty much look to be the same thing if I'm doing my own drawing & the object won't have any children, however there seems to be a pref for subclassing JPanel over JComponent - just looking for opinions on why this might be ...

Thx :-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

顾北清歌寒 2024-07-20 05:52:43

如果您自己绘制整个组件,请使用 JComponent。 JPanel 只是 JComponent(它是抽象的)的一个简单的具体实例,并不真正意味着要重写它的方法。

JPanel 有时会被子类化,以便子类构造函数可以添加各种控件/布局,而不必通过某些方法调用来完成。

If you are drawing the whole component yourself, then use JComponent. JPanel is just a simple concrete instance of JComponent (which is abstract), and is not really meant to have its methods overridden.

JPanel is sometimes subclassed so that the subclass constructor can add various controls/layout rather than having to do it via some method call.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文