开发者

jTable beansbinding

I insert data from a util.List into a JTable with beansbinding.I have wrapped an ArrayList into a ObservableList and Observable list assinged to uitl.List.I bound data in Netbeans and set up properties in 'Table Content' in Netbeans 'JTable Beanbinding options'. First time when the list is updated, the JTable is also updated and it is ok. But second time when I set another util.List which is cast into Observable list to the list which is bound to the JTable, the list is updated, but JTable is not updated.(but when I set a list,the System.out.pr.. prints correct values of the list,here I changed the util.List to ObservableList and vise versa to find where the problem is,but no result as I expected)(but when I add objects to the list bound to JTable, then JTable was updated.) How can I update the JTable when the list is updated(That means when I set a new list,the table is also updated every time I set a new list).

Here is my code used to set Li开发者_开发问答st

 public List<Customer> getSuggestionList() {
    return suggestionList;
 }

public void setSuggestionList(ObservableList suggestionList) {

    try {
        List oldSuggestionList = this.suggestionList;
        this.suggestionList = suggestionList;
        propertySupport.firePropertyChange(PROP_SUGGESTIONLIST, oldSuggestionList, suggestionList);

        System.out.println("Suggestionlist is setted-----------");
        Customer c = (Customer) suggestionList.get(0);
        System.out.println("sugesstion list customer--------" + c.getCustFname());
    } catch (Exception e) {
        e.printStackTrace();
    }
}


Just checked: it's working as expected (manual coding of course, wouldn't touch Netbeans ), sourceBean the class which has the property suggestionList;

    BindingGroup context = new BindingGroup();
    BeanProperty valuesProperty = BeanProperty.create("suggestionList");

    JTableBinding tableBinding = SwingBindings.createJTableBinding(
            UpdateStrategy.READ_WRITE,
            sourceBean, valuesProperty,
            table);
    context.addBinding(tableBinding);
    tableBinding.addColumnBinding(BeanProperty.create("firstName"));
    tableBinding.addColumnBinding(BeanProperty.create("lastName"));
    context.bind();

    // add a button which changes the suggestionList 
    Action next = new AbstractAction("new data") {

        public void actionPerformed(ActionEvent e) {
            sourceBean.setSuggestionList(createRandomData());
        }

    };
    button.setAction(next);

summary: something is wrong with the code you are not showing ;-)

BTW: the getters/setters signatures should have the same type, which yours dont. Doesn't make a difference in my test, in your context might or might not indicate some unwanted mixup

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜