General design problem with Observable

I would like my subclassed JTree to be Observable and notify observers when the selection changes.But I can't extend from JTree and Observable at the same time.I must be braindead today or something, but please enlighten me :)
[255 byte] By [borbjoa] at [2007-9-28 10:59:03]
# 1

Your JTree already has the following method:

addTreeSelectionListener

public void addTreeSelectionListener(TreeSelectionListener tsl)

Adds a listener for TreeSelection events.

Parameters:

tsl - the TreeSelectionListener that will be notified when a node is selected or deselected (a "negative selection")

tsitha at 2007-7-12 1:13:56 > top of Java-index,Other Topics,Patterns & OO Design...
# 2

If you are faced with a similar kind of problem again, and it can't be solved as conveniently as with tsith's solution - interfaces! Just define some kind of listener interface that has some kind of update method, then an interface that allows you to add objects of the first interface as listeners. No-one really uses the Observer stuff.

moschopsa at 2007-7-12 1:13:56 > top of Java-index,Other Topics,Patterns & OO Design...