views:

488

answers:

1

Hi,

I have this JList (say MyList) in a JFrame. Im using Netbeans6 GUI builder and I've set a binding for this list.

When run, the binding works fine, and MyList is populated correctly.

Now, what im looking for is a way to add more data to this list from another text box on a button Click. But the problem exists here :

W/o binding i would extract the ListModel for the JList using "getModel()" function and add element to it using "addElement()".

However, when im using Binding. and i try to extract the ListModel and Map it to DefaultListModel i get the following exception:

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: org.jdesktop.swingbinding.JListBinding$BindingListModel cannot be cast to javax.swing.DefaultListModel

So my question is , how do i add more elements to MyList which is already bound to some other dataSource ?

Anyone has any clues ? Any Help will greatly appreciated!!

Thanks!

A: 

You have to modify the List to which the JList is bound. And this List must be an Observable list for the change to be registered. The point of binding is that you don't manipulate components' models anymore, but their underlaying data types instead.

Thanks for the reply! Its been quite some time i had asked this question, and have already worked around that problem. But for others facing the same issue, this answer makes sense to me! I haven't tried though, but should work this way!Thanks!
Abhishek