JavaFX 2: Tables: Update display after having updated data

跟風遠走 提交于 2019-12-07 18:43:52

问题


This is all I need to finish answering my last question.

If you look at my last question, you will see my class, containing four fields, corresponding to the four columns of my table

public static class ContactOptions {

    private final StringProperty one;
    private final StringProperty two;
    private final StringProperty three;
    private final StringProperty four;

    ContactOptions(String col1, String col2, String col3, String col4) {
        this.one = new StringProperty(col1);
        this.two = new StringProperty(col2);
        this.three = new StringProperty(col3);
        this.four = new StringProperty(col4);
    }

    public String getOne() {
        return one.get();
    }

    public String getTwo() {
        return two.get();
    }

    public String getThree() {
        return three.get();
    }

    public String getFour() {
        return four.get();
    }
}

How do I get the GUI to update after I run ContactOptions.one.set?

When I scroll down and back up, it updates. How can I get it to update without scrolling.

I also asked this at https://forums.oracle.com/forums/thread.jspa?threadID=2275725


回答1:


Maybe you should use one of the methods below:

updateTableColumn(TableColumn col) 

Updates the TableColumn associated with this TableCell.

updateTableRow(TableRow tableRow) 

Updates the TableRow associated with this TableCell.

updateTableView(TableView tv) 

Updates the TableView associated with this TableCell.

(From http://docs.oracle.com/javafx/2.0/api/javafx/scene/control/TableCell.html)

But I think you had already handled this problem)




回答2:


For updates to work seamlessly, you should initialize each property and add the xxxProperty method:

private final StringProperty one = new SimpleIntegerProperty();

public StringProperty oneProperty() {
   return one;
}

From my own experience, do not use property names using upperCase letters, like "myOne" or "myONE", as the xxxProperty method won't run.




回答3:


Which build of JavaFX 2.0 are you using? The reason I ask is that tables changed recently and I want to make sure you are using the latest version.



来源:https://stackoverflow.com/questions/7237714/javafx-2-tables-update-display-after-having-updated-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!