Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JavaFX - modifying an item in the observable list doesn't update a ListView

2767218Oct 3 2014 — edited Oct 3 2014

I am using:

  • Java:..... 1.8.0_20
  • JavaFX:... 8.0.20-b26

I have this class:

public class Person {

    private SimpleStringProperty name;

    public SimpleStringProperty nameProperty(){

        if(this.name==null){

            this.name=new SimpleStringProperty();

        }

        return this.name;

    }

    public final void setName(String value){

        nameProperty().set(value);

    }

    public String getName(){

        return nameProperty().get();

    }

    public Person(String value){

        setName(value);

    }

    public String toString(){

        return this.getName();

    }

}


I have this:

lista = FXCollections.<Person>observableArrayList();

lista.addAll(new Person("uno"),new Person("due"),new Person("tre"));

myListView.setItems(lista);


the problem is if I add /remove an item all is fine, the listView refreshes correctly:

Person p = new Person(tfld_textAdd.getText());

lista.add(0, p);

but if I change a value on an item into the observable list it doesn't:

lista.get(0).setName("new value");

I also have a table linked in the same way and the table workd correctly after I updated my Java version...

Thanks in advance.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 31 2014
Added on Oct 3 2014
2 comments
2,032 views