JavaFX 2: Tables: Update display after having updated data


Question

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
2
7/29/2017 10:29:46 PM

Accepted Answer

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
3/19/2012 11:29:01 AM

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.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon