It is my understanding that the code example I posted showed composition, not derivation. It *contained* a reference to a JPanel rather than extending from one.
Anyway, can you guys can confirm that what I was trying to do (having a class which extends JComponent, contains a JPanel and delegates it's methods to the JPanel) is not possible?
What I want is something which
* Looks and acts like any other...
User Profile
Collapse
-
-
It's just not very nice -
My widget really isn't a panel, it's something in it's own right that just happens to want to take advantage of functionality which exists in JPanel rather than rewriting it from scratch.
If I extend from JPanel then I expose a whole lot of methods which I don't want to.
For example:
public void add(Component c)
I don't want people adding things...Leave a comment:
-
JComponent - delegating to JPanel
Hi, I want to write a custom widget which will act similarly to a JPanel (i.e it can contain other Components), but semantically it's not a kind of JPanel so it shouldn't extend from it.
Here is some sample code showing what I'm trying to achieve:
Effectively I expect to see a JLabel with the message "This is a test" as well as a JButton "foo".
What am I doing wrong? Is this possible? Also,...
No activity results to display
Show More
Leave a comment: