I would like to create a new Swing JComponent based on an existing one, but with a different API. In other words, I don\'t want to extend the existing component, because I don\'
You can create MyJComponent
subclass of JComponent
with a private field that references a forwarding class for ExistingComponent
.
The interactions with ExistingComponent
are done with the forwarding class through methods of MyJComponent
, and you are free to add more methods to MyJComponent
.
Please see Effective Java item 16, for the delegation pattern used with the forwarding class.