I tried to bind a JList to a binding class property, Vector. In the binding class, the Vector is updated when a JTextField in UI is updated.
public void setName(String name) {
String oldName = this.name;
this.name = name;
Vector oldList=this.list;
list.add(name);
propertySupport.firePropertyChange("name", oldName, this.name); //textField updates
propertySupport.firePropertyChange(PROP_LIST, oldList, list); // JList
}
Also another seperate setter is available for updating the Vector. I have set add/remove PropertyChangeListeners as well.
My real requirement is to update the JList according to data in BeanBinding class. For example, when the user types in JTextField, relevant data from database and existing variables in class should be loaded into the JList.
Please, any one let me know how to bind data BeanBinding class (source) property for a JList in NetBeans. At least any tutorial link. There is a sample in NetBeans site, but it is for getting data directly from database.
Don’t know about Netbeans, just menial coding 🙂 In that, wrap your list into an ObservableList and do all changes on the observable should work. Here’s a runnable code snipped (sorry for the length, don’t have the energy to strip it down right now)
Edit: replaced JXList by JList (no difference in behaviour, just to make it compileable 🙂