Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
698 views
in Technique[技术] by (71.8m points)

javafx 2 - Autoupdating rows in TableView from model

I've been looking information about refreshing data into a tableview. I was trying modifying directly the model, but I get a bug. I modify the model, but the table doesn't refreshed, only when I move a column, the table shows the modified values.

To show you an example (13-6) I take the tutorial:

http://docs.oracle.com/javafx/2/ui_controls/table-view.htm#CJABIEED

And I modify it including a button and in its action:

Button button = new Button("Modify");
button.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent arg0) {
    String name = table.getItems().get(0).getFirstName();
    name = name + "aaaa";
    table.getItems().get(0).setFirstName(name);
    }
});

final VBox vbox = new VBox();
vbox.setSpacing(5);
vbox.getChildren().addAll(label, table, button);
vbox.setPadding(new Insets(10, 0, 0, 10));

I guess that it's a bug in the tableview, but is there any chance to fix this?

Thank you!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

to make TableView able to track data changes you need to expose relevant fields as JavaFX properties. Add next methods to Person class from tutorial:

    public SimpleStringProperty firstNameProperty() {
        return firstName;
    }

    public SimpleStringProperty lastNameProperty() {
        return lastName;
    }

    public SimpleStringProperty emailProperty() {
        return email;
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...