簡體   English   中英

jTable beansbinding

[英]jTable beansbinding

我將util.List中的數據插入到帶有beansbinding的JTable中。我將一個ArrayList包裝到一個ObservableList和Observable列表中,該列表被綁定到Netbeans中的uitl.List.I綁定數據,並在Netbeans的JTable Beanbinding中的'Table Content'中設置屬性選項。 第一次更新列表時,JTable也會更新,沒關系。 但是第二次當我將另一個被嵌入Observable列表的util.List添加到綁定到JTable的列表時,列表會更新,但JTable不會更新。(但是當我設置一個列表時,System.out。 pr ..打印列表的正確值,這里我將util.List更改為ObservableList,反之亦然,找到問題所在,但沒有結果如我所料)(但是當我將對象添加到綁定到JTable的列表中時, JTable已更新。)如何更新列表時更新JTable(這意味着當我設置新列表時,每次設置新列表時表也會更新)。

這是我用來設置List的代碼

 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();
    }
}

剛檢查:它按預期工作(手動編碼當然不會觸及Netbeans),sourceBean具有屬性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);

摘要:你沒有顯示的代碼有問題;-)

BTW:getters / setters簽名應該具有相同的類型,而不是你的。 在我的測試中沒有任何區別,在你的上下文中可能會或可能不會表示一些不必要的混淆

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM