As per the class hierarchy in java.awt.*
, class Button
& class Label
is-a
class Component
, and Component is not a Container, which make sense to me.
As per the redesign of class hierarchy in javax.swing.*
, class JButton
is-a
class JComponent
in-turn class JComponent
is-a class Container
,
So, What does it mean to say that, class JButton
or class JRadioButton
is-a
class Container
? How could one think of using button or radiobutton as container in GUI programming?
Note: I am java beginner.
What does it mean to say that,
class JButton
orclass JRadioButton
is-aclass Container
?
The reason why all Swing components are derived from java.awt.Container
is mostly for practical reasons which are internal to the implementation of Swing. AWT and Swing usually will not be mixed. But internally, a Swing component might realize itself using more than one AWT component, and that’s purely up to the Swing component itself.
How could one think of using button or radiobutton as container in GUI programming?
The fact that Swing components extend java.awt.Container
can and should mostly be ignored. One shouldn’t mess around with the java.awt.Container
methods of Swing components unless it’s obvious that it makes sense (which is the case for most if not all *Pane
components and javax.swing.JPanel
).
7