Reputation: 208
I want to create a radio button that has more components than the default JRadioButton. I'm wondering what the best method is, should I subclass JRadioButton adding my extra components or is it better to subclass JPanel and add the behavior of a radio button as shown below.
---------JPanel---------------
- Titel (Label) -
- RadioButton (JRadioButton) -
- Description (label) -
------------------------------
The whole panel should be focusable and should provide feedback when clicked or has focus. Thanks for your help.
Upvotes: 0
Views: 75
Reputation: 205775
None of the above.
Don't extend components unless you genuinely need to extend functionality, especially not merely for decoration.
Don't confuse the containment hierarchy with the class hierarchy.
Don't defeat the existing focus subsystem unless you plan to provide your own.
If you want to alter the appearance of the panel when the radio button's focus changes, do so in a focus listener attached to the button. The background color of an opaque panel is a bound property, so setBackground()
should be sufficient.
Upvotes: 1