Java Swing: customize everything – subclass JComponent or JPanel or?

Hiya – the fast one – does the subclassing of JComponent have any damage / value compared to JPanel?

For me, if I'm making my own drawings and amplifiers, they look almost the same The object will not have any children, but there seems to be a pref to subclass JPanel to JComponent - just looking for advice on why this might be

Thank you: -)

Solution

If you draw the entire component yourself, use JComponent JPanel is just a simple concrete instance of JComponent (it is abstract), which does not really mean that its methods are overwritten

JPanel is sometimes a subclass, so the subclass constructor can add various controls / layouts without some method calls

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>